
//LPDDR0:0x4,0000,0000
//LPDDR1:0x6,0000,0000
//REG:	 0x8,0000,0000 
//8,0000,0000-8,1000,0000 //APB_RAM
//8,1000,0000-8,3000,0000 //LPDDR0_REG
//8,3000,0000-8,5000,0000 //LPDDR1_REG



//////////////////20220910//////////////////////


#define REG_BASEADDR 	  0x800000000    

#define DDR0_BASEADDR 	  0x80000000    //8GB 0x8000,0000-0x2,8000,0000

#define DDR0_BASEADDR_2GB 0x17FFFF000   //8GB- 4096 ADDRESS

#define DDR1_BASEADDR 	  0x280000000   //8GB 0x2,8000,0000-0x4,8000,0000

#define DDR1_BASEADDR_2GB 0x37FFF0000   //8GB- 4096 ADDRESS


#define LPDDR0_REG0_BASEADDR 	  0x31000000   
#define LPDDR0_REG1_BASEADDR 	  0x32000000   

#define LPDDR1_REG0_BASEADDR 	  0x33000000   
#define LPDDR1_REG1_BASEADDR 	  0x34000000 

typedef unsigned int int32_t;

#define APB_SLAVE ((volatile int32_t *)REG_BASEADDR)

#define DDR0_SLAVE ((volatile int32_t *)DDR0_BASEADDR)
#define DDR1_SLAVE ((volatile int32_t *)DDR1_BASEADDR)

#define DDR0_SLAVE_2GB ((volatile int32_t *)DDR0_BASEADDR_2GB)
#define DDR1_SLAVE_2GB ((volatile int32_t *)DDR1_BASEADDR_2GB)

#define LPDDR0_CTRL  ((volatile int32_t *)LPDDR0_REG0_BASEADDR)
#define LPDDR0_PHY   ((volatile int32_t *)LPDDR0_REG1_BASEADDR)

#define LPDDR1_CTRL  ((volatile int32_t *)LPDDR1_REG0_BASEADDR)
#define LPDDR1_PHY   ((volatile int32_t *)LPDDR1_REG1_BASEADDR)


//#define APB_BASEADDR 	  0x30023020  
#define APB_BASEADDR 	  0x30680020 
#define APB   ((volatile int32_t *)APB_BASEADDR)


#define INTLEAVE_BASEADDR 	  0x30024F00  
#define INTLEAVE   ((volatile int32_t *)INTLEAVE_BASEADDR)
//////////////////20220910//////////////////////

void ddr_test_1600()
{

	unsigned int ddr_start = 0x90000000;
    unsigned int ddr_end   = 0x91000000;

    unsigned int test_add = ddr_start;
    unsigned int read_test_addr = 0;

    printf(" ---- test addr begin 1600 \n");

    unsigned int  *src0_addr;
    unsigned int  *src1_addr;
    unsigned int  *src2_addr;
    unsigned int  *src3_addr;

    unsigned int  err_cnt=0;
    unsigned int  read_data;
    unsigned int  i = 0;

    src0_addr=(volatile unsigned int*)DDR0_BASEADDR_2GB;
    src1_addr=(volatile unsigned int*)DDR1_BASEADDR_2GB;
    src2_addr=(volatile unsigned int*)DDR0_BASEADDR_2GB;
    src3_addr=(volatile unsigned int*)DDR1_BASEADDR_2GB;



    for(i=0;i<1048576;i++){
    	src0_addr[i]=0x0;
    //	src0_addr[i]=0xffffffff;
    //	src1_addr[i]=0x87654321+i;
    }

    for(i=0;i<1048576;i++){
    //	src0_addr[i]=0x0;
    //	src0_addr[i]=0xffffffff;
    	src0_addr[i]=0x87654321+i;
    }



    for(int i=0;i<1048576;i++){

   // 	if(err_cnt > 8192){
//
 //   		break;
 //   	}

        read_data = DDR0_SLAVE_2GB[i];

    	if(read_data != (0x87654321+i)){
    		err_cnt++;
    	//	printf("\n data  is %x!\n", read_data);
    		printf("addr is:%x  data is:%x \n",i,read_data);
    	}
    }

    printf("addr is:%x  data is:%x \n",i,read_data);

    printf("\n err  is %x!\n", err_cnt);




    while(test_add < ddr_end){
        //*(volatile unsigned int*)(test_add) = test_add;
        *(volatile unsigned int*)(test_add) = 0xa5a5a5a5;

        read_test_addr = *(volatile unsigned int*)(test_add);

        if(read_test_addr != 0xa5a5a5a5){
            printf(" ---- test addr fail \n");
            printf("read_test_addr:%x  test_add:%x \n",read_test_addr,test_add);
            break;
        }else{
            test_add = test_add + 4;
            if((test_add % 0x100000) == 0)
                printf(" ---- test addr : %x \n",test_add);
        }

    }




}


void ddr_config_1600()
{  
	//uart_init(UART0,115200);

//#ifdef ADDR_INTLEAVE

//	INTLEAVE[0x0/4]=0x0;

//#else

	INTLEAVE[0x0/4]=0x1;
//#endif


	APB[0x0/4]=0x3d80000;
	//0x30680044-PLL2 set
	APB[0x24/4]=0xa27;

	unsigned int i = 0,error=0,rdata = 0;
	unsigned int read_data = 0;
	unsigned int READ_DATA = 0;

	//APB_SLAVE[0x0/4] = 0;

/*
	int *picr = REG_BASEADDR;
     
	for (i=0;i<20;i++)
	{
		 *picr = i;
		 rdata = *picr;
		 if(rdata != i){
 			printf("\n num is %x!\n",i);
			printf("\n r is %x!\n",rdata);
		 	error++;
		// 	break;
		 }
		*picr++;
	}
	 
	
 	printf("\nerror  is %x!\n",error);



*/


LPDDR0_CTRL[0x270/4]= 0x48fa;
LPDDR0_CTRL[0x270/4]= 0x491a;
LPDDR0_CTRL[0x270/4]= 0x471a;
LPDDR0_CTRL[0x270/4]= 0x471a;
LPDDR0_CTRL[0x270/4]= 0x471a;
LPDDR0_CTRL[0x274/4]= 0x3020100;
LPDDR0_CTRL[0x274/4]= 0x3020100;
LPDDR0_CTRL[0x274/4]= 0x3020100;
LPDDR0_CTRL[0x274/4]= 0x3020100;
LPDDR0_CTRL[0x278/4]= 0x7060504;
LPDDR0_CTRL[0x278/4]= 0x7060504;
LPDDR0_CTRL[0x278/4]= 0x70a0504;
LPDDR0_CTRL[0x278/4]= 0xb0a0504;
LPDDR0_CTRL[0x27c/4]= 0x90c;
LPDDR0_CTRL[0x27c/4]= 0x90c;
LPDDR0_CTRL[0x27c/4]= 0x90c;
LPDDR0_CTRL[0x27c/4]= 0x90c;
LPDDR0_CTRL[0x280/4]= 0xd0c0b0d;
LPDDR0_CTRL[0x280/4]= 0xd0c0e0d;
LPDDR0_CTRL[0x280/4]= 0xd0f0e0d;
LPDDR0_CTRL[0x280/4]= 0x100f0e0d;
LPDDR0_CTRL[0x284/4]= 0x11100f11;
LPDDR0_CTRL[0x284/4]= 0x11101211;
LPDDR0_CTRL[0x284/4]= 0x11131211;
LPDDR0_CTRL[0x284/4]= 0x14131211;
LPDDR0_CTRL[0x288/4]= 0x15141315;
LPDDR0_CTRL[0x288/4]= 0x15141615;
LPDDR0_CTRL[0x288/4]= 0x15171615;
LPDDR0_CTRL[0x288/4]= 0x18171615;
LPDDR0_CTRL[0x28c/4]= 0x19181719;
LPDDR0_CTRL[0x28c/4]= 0x19181a19;
LPDDR0_CTRL[0x28c/4]= 0x191b1a19;
LPDDR0_CTRL[0x28c/4]= 0x1c1b1a19;
LPDDR0_CTRL[0x290/4]= 0x1d;
LPDDR0_CTRL[0x290/4]= 0x1d;
LPDDR0_CTRL[0x294/4]= 0x1c1b06;
LPDDR0_CTRL[0x294/4]= 0x1c0706;
LPDDR0_CTRL[0x294/4]= 0x80706;
LPDDR0_CTRL[0x294/4]= 0x80706;
LPDDR0_CTRL[0x298/4]= 0x1e1e;
LPDDR0_CTRL[0x298/4]= 0x1e;
LPDDR0_CTRL[0x2a4/4]= 0x268254;
LPDDR0_CTRL[0x2a4/4]= 0xb5028254;
LPDDR0_CTRL[0x2b0/4]= 0x1f8000;
LPDDR0_CTRL[0x2b0/4]= 0x1f0900;
LPDDR0_CTRL[0x2ac/4]= 0xc4425ab0;
LPDDR0_CTRL[0x64/4]= 0x0;
LPDDR0_CTRL[0x64/4]= 0xd6000000;
LPDDR0_CTRL[0x64/4]= 0xd6000000;
LPDDR0_CTRL[0x64/4]= 0xd6000000;
LPDDR0_CTRL[0x64/4]= 0xd6980000;
LPDDR0_CTRL[0x64/4]= 0xd6980001;
LPDDR0_CTRL[0x64/4]= 0xd698ae01;
LPDDR0_CTRL[0x2a0/4]= 0x3;
LPDDR0_CTRL[0x0/4]= 0x3fd04480;
LPDDR0_CTRL[0x2e4/4]= 0x1;
LPDDR0_CTRL[0x2e4/4]= 0x1;
LPDDR0_CTRL[0x124/4]= 0x0;
LPDDR0_CTRL[0x0/4]= 0x3fd04480;
LPDDR0_CTRL[0x70/4]= 0x0;
LPDDR0_CTRL[0x560/4]= 0x1ff;
LPDDR0_CTRL[0x178/4]= 0x80700;
LPDDR0_CTRL[0x0/4]= 0x3fd04500;
LPDDR0_CTRL[0x0/4]= 0x3fd04500;
LPDDR0_CTRL[0x0/4]= 0x3d04500;
LPDDR0_CTRL[0x160/4]= 0xff0503;
LPDDR0_CTRL[0x160/4]= 0xff0503;
LPDDR0_CTRL[0x0/4]= 0x3d04505;
LPDDR0_CTRL[0x2e4/4]= 0x0;
LPDDR0_CTRL[0x2e4/4]= 0xd300;
LPDDR0_CTRL[0x98/4]= 0x101f0000;
LPDDR0_CTRL[0x56c/4]= 0x20a;
LPDDR0_CTRL[0x2b8/4]= 0x10;
LPDDR0_CTRL[0x88/4]= 0x4040;
LPDDR0_CTRL[0x8c/4]= 0x308086c;
LPDDR0_CTRL[0x124/4]= 0x0;
LPDDR0_CTRL[0x70/4]= 0x0;
LPDDR0_CTRL[0x12c/4]= 0x0;
LPDDR0_CTRL[0x130/4]= 0x6fffffff;
LPDDR0_CTRL[0x180/4]= 0x10004080;
LPDDR0_CTRL[0x180/4]= 0x10004040;
LPDDR0_CTRL[0x90/4]= 0x8083100;
LPDDR0_CTRL[0x90/4]= 0x8083190;
LPDDR0_CTRL[0x90/4]= 0x8083190;
LPDDR0_CTRL[0x8c/4]= 0x373086c;
LPDDR0_CTRL[0x8c/4]= 0x373086c;
LPDDR0_CTRL[0x90/4]= 0x8633190;
LPDDR0_CTRL[0x90/4]= 0x6a633190;
LPDDR0_CTRL[0x140/4]= 0x1421232;
LPDDR0_CTRL[0x140/4]= 0x1420142;
LPDDR0_CTRL[0x160/4]= 0xff0503;
LPDDR0_CTRL[0x5a8/4]= 0xff001a;
LPDDR0_CTRL[0x164/4]= 0xff001a;
LPDDR0_CTRL[0x164/4]= 0xff001a;
LPDDR0_CTRL[0x5a8/4]= 0xff001a;
LPDDR0_CTRL[0x56c/4]= 0x20a;
LPDDR0_CTRL[0x564/4]= 0x4040510;
LPDDR0_CTRL[0x56c/4]= 0x20a;
LPDDR0_CTRL[0x564/4]= 0x8040510;
LPDDR0_CTRL[0x564/4]= 0x8040510;
LPDDR0_CTRL[0x56c/4]= 0x40a;
LPDDR0_CTRL[0x55c/4]= 0x80000000;
LPDDR0_CTRL[0x60/4]= 0x200203;
LPDDR0_CTRL[0x60/4]= 0x202203;
LPDDR0_CTRL[0x7c/4]= 0x20001;
LPDDR0_CTRL[0x2e8/4]= 0x30200;
LPDDR0_CTRL[0x59c/4]= 0x4000000;
LPDDR0_CTRL[0x59c/4]= 0x4003000;
LPDDR0_CTRL[0x59c/4]= 0x40a3000;
LPDDR0_CTRL[0x59c/4]= 0x40a3020;
LPDDR0_CTRL[0x598/4]= 0x2008;
LPDDR0_PHY[0x22c/4]= 0x20f06e;
LPDDR0_PHY[0x144/4]= 0x120000;
LPDDR0_PHY[0x2fc/4]= 0x7e00000;
LPDDR0_CTRL[0x58c/4]= 0x0;
LPDDR0_CTRL[0x168/4]= 0x3ff0ff80;
LPDDR0_CTRL[0x168/4]= 0x3ff08000;
LPDDR0_CTRL[0x530/4]= 0xffffff80;
LPDDR0_CTRL[0x530/4]= 0xfff07f80;
LPDDR0_CTRL[0x120/4]= 0x1;
LPDDR0_CTRL[0x2b4/4]= 0x41010;
LPDDR0_CTRL[0x55c/4]= 0x8000001c;
LPDDR0_CTRL[0x558/4]= 0x7;
LPDDR0_CTRL[0x554/4]= 0x3f;
LPDDR0_CTRL[0x40/4]= 0xf1f;
LPDDR0_CTRL[0x40/4]= 0x8d1f;
LPDDR0_CTRL[0x28/4]= 0x20040001;
LPDDR0_CTRL[0x38/4]= 0x160f0f0f;
LPDDR0_CTRL[0x18/4]= 0x80f0f0f;
LPDDR0_CTRL[0x38/4]= 0x16100f0f;
LPDDR0_CTRL[0x3c/4]= 0x2b0f0f0f;
LPDDR0_CTRL[0x38/4]= 0x16100f08;
LPDDR0_CTRL[0x3c/4]= 0x2b0f290f;
LPDDR0_CTRL[0x3c/4]= 0x2b22290f;
LPDDR0_CTRL[0x3c/4]= 0x2b222913;
LPDDR0_CTRL[0x570/4]= 0x51f;
LPDDR0_CTRL[0x4/4]= 0x11000f;
LPDDR0_CTRL[0x4/4]= 0x110010;
LPDDR0_CTRL[0x8/4]= 0x4f4;
LPDDR0_CTRL[0xc/4]= 0xf0024;
LPDDR0_CTRL[0x20/4]= 0x23e017;
LPDDR0_CTRL[0x34/4]= 0x1740f0f;
LPDDR0_CTRL[0xc/4]= 0x100024;
LPDDR0_CTRL[0x10/4]= 0xf0008;
LPDDR0_CTRL[0x10/4]= 0x80008;
LPDDR0_CTRL[0x28/4]= 0x20040001;
LPDDR0_CTRL[0x14/4]= 0xf150f0f;
LPDDR0_CTRL[0x14/4]= 0xf150a0f;
LPDDR0_CTRL[0x14/4]= 0xf150a08;
LPDDR0_CTRL[0x18/4]= 0x80b0f0f;
LPDDR0_CTRL[0x18/4]= 0x80b080f;
LPDDR0_CTRL[0x18/4]= 0x80b0808;
LPDDR0_CTRL[0x14/4]= 0x20150a08;
LPDDR0_CTRL[0x24/4]= 0x9050000;
LPDDR0_CTRL[0x2c/4]= 0x5000009;
LPDDR0_CTRL[0x30/4]= 0x1380200;
LPDDR0_CTRL[0x30/4]= 0x1380000;
LPDDR0_CTRL[0x34/4]= 0x174980f;
LPDDR0_CTRL[0x2c/4]= 0x3000009;
LPDDR0_CTRL[0x24/4]= 0x9080000;
LPDDR0_CTRL[0x178/4]= 0x140700;
LPDDR0_CTRL[0x178/4]= 0x140500;
LPDDR0_CTRL[0x178/4]= 0xe140500;
LPDDR0_CTRL[0x2c/4]= 0x3050009;
LPDDR0_CTRL[0x2b4/4]= 0x4c410;
LPDDR0_CTRL[0x50/4]= 0x3000000;
LPDDR0_CTRL[0x50/4]= 0x3001800;
LPDDR0_CTRL[0x1c/4]= 0x50000000;
LPDDR0_CTRL[0x1c/4]= 0x50000500;
LPDDR0_CTRL[0x1c/4]= 0x500c0500;
LPDDR0_CTRL[0x1c/4]= 0x500c0504;
LPDDR0_CTRL[0x38/4]= 0x16100a08;
LPDDR0_CTRL[0x2c/4]= 0x3051409;
LPDDR0_CTRL[0x28/4]= 0x20040010;
LPDDR0_CTRL[0x20/4]= 0x74a017;
LPDDR0_CTRL[0x24/4]= 0x9080064;
LPDDR0_CTRL[0x50/4]= 0x9c30d190;
LPDDR0_CTRL[0x80/4]= 0xc004000;
LPDDR0_CTRL[0x28/4]= 0x20040c10;
LPDDR0_CTRL[0x80/4]= 0xc004019;
LPDDR0_CTRL[0x9c/4]= 0x70c;
LPDDR0_CTRL[0x9c/4]= 0xc0c;
LPDDR0_CTRL[0x94/4]= 0x30f;
LPDDR0_CTRL[0x94/4]= 0x303;
LPDDR0_CTRL[0x2b4/4]= 0x4c400;
LPDDR0_CTRL[0x28/4]= 0x20040c10;
LPDDR0_CTRL[0x44/4]= 0x11000f;
LPDDR0_CTRL[0x44/4]= 0x11bbe5;
LPDDR0_CTRL[0x48/4]= 0x14000f;
LPDDR0_CTRL[0x48/4]= 0x140024;
LPDDR0_CTRL[0x4c/4]= 0xc000f;
LPDDR0_CTRL[0x4c/4]= 0xc000c;
LPDDR0_CTRL[0x2ec/4]= 0xd000000;
LPDDR0_CTRL[0x2ec/4]= 0xd000124;
LPDDR0_CTRL[0x2f0/4]= 0x2120000;
LPDDR0_CTRL[0x2f0/4]= 0x2120318;
LPDDR0_CTRL[0x2f4/4]= 0xb000000;
LPDDR0_CTRL[0x2f4/4]= 0xb000c4d;
LPDDR0_CTRL[0x2f8/4]= 0xe000000;
LPDDR0_CTRL[0x2f8/4]= 0xe001600;
LPDDR0_CTRL[0x2fc/4]= 0xd000000;
LPDDR0_CTRL[0x2fc/4]= 0xd000124;
LPDDR0_CTRL[0x300/4]= 0x2120000;
LPDDR0_CTRL[0x300/4]= 0x2120318;
LPDDR0_CTRL[0x304/4]= 0xb000000;
LPDDR0_CTRL[0x304/4]= 0xb000c4d;
LPDDR0_CTRL[0x308/4]= 0xe000000;
LPDDR0_CTRL[0x308/4]= 0xe001600;
LPDDR0_CTRL[0x30c/4]= 0xd000000;
LPDDR0_CTRL[0x30c/4]= 0xd000124;
LPDDR0_CTRL[0x310/4]= 0x2120000;
LPDDR0_CTRL[0x310/4]= 0x2120318;
LPDDR0_CTRL[0x314/4]= 0xb000000;
LPDDR0_CTRL[0x314/4]= 0xb000c4d;
LPDDR0_CTRL[0x318/4]= 0xe000000;
LPDDR0_CTRL[0x318/4]= 0xe001600;
LPDDR0_CTRL[0x31c/4]= 0xd000000;
LPDDR0_CTRL[0x31c/4]= 0xd000124;
LPDDR0_CTRL[0x320/4]= 0x2120000;
LPDDR0_CTRL[0x320/4]= 0x2120318;
LPDDR0_CTRL[0x324/4]= 0xb000000;
LPDDR0_CTRL[0x324/4]= 0xb000c4d;
LPDDR0_CTRL[0x328/4]= 0xe000000;
LPDDR0_CTRL[0x328/4]= 0xe001600;
LPDDR0_PHY[0x0/4]= 0x60000f57;
LPDDR0_PHY[0x0/4]= 0x60000f57;
LPDDR0_PHY[0x20/4]= 0xe440;
LPDDR0_PHY[0x1c/4]= 0x10020013;
LPDDR0_PHY[0x48/4]= 0x3d00000;
LPDDR0_PHY[0xac/4]= 0x0;
LPDDR0_PHY[0xac/4]= 0x0;
LPDDR0_PHY[0xac/4]= 0x2000;
LPDDR0_PHY[0x48/4]= 0x3d00000;
LPDDR0_PHY[0xac/4]= 0x3000;
LPDDR0_PHY[0x48/4]= 0x3d00000;
LPDDR0_PHY[0x10/4]= 0x8000000;
LPDDR0_PHY[0xc/4]= 0xe060606;
LPDDR0_PHY[0x8/4]= 0x0;
LPDDR0_PHY[0xa8/4]= 0x25819880;
LPDDR0_PHY[0xa8/4]= 0xaf19880;
LPDDR0_PHY[0xdc/4]= 0x4901b080;
LPDDR0_PHY[0x284/4]= 0x80000077;
LPDDR0_PHY[0x54/4]= 0x10203;
LPDDR0_PHY[0x54/4]= 0x10203;
LPDDR0_PHY[0x54/4]= 0x10203;
LPDDR0_PHY[0x54/4]= 0x10203;
LPDDR0_PHY[0x58/4]= 0x4050607;
LPDDR0_PHY[0x58/4]= 0x4050607;
LPDDR0_PHY[0x640/4]= 0x10003;
LPDDR0_PHY[0x940/4]= 0x30003;
LPDDR0_PHY[0xc40/4]= 0x50003;
LPDDR0_PHY[0xf40/4]= 0x70003;



//dqmap
LPDDR0_PHY[0x6dc/4] = 0x46732015;
LPDDR0_PHY[0x9dc/4] = 0x43570126;
LPDDR0_PHY[0xcdc/4] = 0x67045312;
LPDDR0_PHY[0xfdc/4] = 0x67351204;

LPDDR0_PHY[0x2fc/4]= 0x7e00c00;
LPDDR0_PHY[0x24/4]= 0x1ff;
LPDDR0_PHY[0x24/4]= 0x1ff;
LPDDR0_PHY[0x280/4]= 0xf00fef;

//release system_rstn & ctrl_rstn

//printf("\n 0 rstn\n");

APB[0x0/4] = 0x3c00000;

LPDDR0_CTRL[0x0/4]= 0x3d04515;
LPDDR0_CTRL[0x0/4]= 0x3f04515;
//PHY INIT complete [0]
while ((LPDDR0_CTRL[0x3b0/4] &  0x1)  == 0 );

LPDDR0_CTRL[0x0/4]= 0x3f04505;
LPDDR0_CTRL[0x0/4]= 0x3d04505;
LPDDR0_CTRL[0x3ac/4]= 0x3c0;
LPDDR0_CTRL[0x0/4]= 0x3d0450d;
//SDRAM INIT complete [2]
while ((LPDDR0_CTRL[0x3b0/4] & 0x4 ) == 0);


//////////////////zqcalib//////////
LPDDR0_PHY[0x8C/4]=0x1;
while ((LPDDR0_PHY[0x1fc/4] & 0x10) != 0x10);
LPDDR0_PHY[0x8C/4]=0x0;

LPDDR0_PHY[0x400/4] |= 0x600000;
LPDDR0_PHY[0x700/4] |= 0x600000;
LPDDR0_PHY[0xd00/4] |= 0x600000;
LPDDR0_PHY[0xd00/4] |= 0x600000;

/*
//////////////////zqcalib//////////
//++++++++++++++++++Command Training Start+++++++++++++++++++++++++++.

LPDDR0_PHY[0x400/4]=0x380800a0;
LPDDR0_PHY[0x400/4]=0x380800a0;
LPDDR0_PHY[0x700/4]=0x380800a0;
LPDDR0_PHY[0x700/4]=0x380800a0;
LPDDR0_PHY[0xa00/4]=0x380800a0;
LPDDR0_PHY[0xa00/4]=0x380800a0;
LPDDR0_PHY[0xd00/4]=0x380800a0;
LPDDR0_PHY[0xd00/4]=0x380800a0;
LPDDR0_PHY[0x24/4]=0x1ff;
LPDDR0_PHY[0x20/4]=0x66840;
LPDDR0_PHY[0x34/4]=0x32004d1f;
LPDDR0_PHY[0x3c/4]=0x3f97f3f;
LPDDR0_PHY[0x40/4]=0x3f7f7f7f;
LPDDR0_PHY[0x40/4]=0x3f3f7f7f;
LPDDR0_PHY[0x3c/4]=0x3f93f3f;
LPDDR0_PHY[0x40/4]=0x3f3f3f7f;
LPDDR0_PHY[0x40/4]=0x3f3f3f3f;
LPDDR0_PHY[0x20/4]=0x66840;
LPDDR0_PHY[0x20/4]=0x66840;
LPDDR0_PHY[0x38/4]=0x11c8;
LPDDR0_PHY[0xa0/4]=0x1000000;
LPDDR0_PHY[0x1c4/4]=0x100067aa;
LPDDR0_PHY[0x20/4]=0x66841;
LPDDR0_PHY[0x20/4]=0x66843;

while ((LPDDR0_PHY[0x214/4] & 0xc) != 0xc);

printf("command bus training: 0x%08x\n",LPDDR0_PHY[0x214/4]);

LPDDR0_PHY[0x20/4] =0x66841;
LPDDR0_PHY[0xc0/4] =0x3be00000;
LPDDR0_PHY[0x20/4] =0x66840;
LPDDR0_PHY[0x1b0/4]=0x14280140;
LPDDR0_PHY[0x1b0/4]=0x14280540;
LPDDR0_PHY[0x1b0/4]=0x14280940;
LPDDR0_PHY[0x1b0/4]=0x14280d40;
LPDDR0_PHY[0x1b0/4]=0x14281140;
LPDDR0_PHY[0x1b0/4]=0x14281540;
LPDDR0_PHY[0x1b0/4]=0x14283940;
LPDDR0_PHY[0x1b0/4]=0x14283d40;
LPDDR0_PHY[0x1b0/4]=0x14284140;
LPDDR0_PHY[0x1b0/4]=0x14284540;
LPDDR0_PHY[0x1b0/4]=0x14284940;
LPDDR0_PHY[0x1b0/4]=0x14284d40;
LPDDR0_PHY[0x400/4]=0x3a0800a0;
LPDDR0_PHY[0x700/4]=0x3a0800a0;
LPDDR0_PHY[0xa00/4]=0x3a0800a0;
LPDDR0_PHY[0xd00/4]=0x3a0800a0;
*/
//++++++++++++++++++Command Training end+++++++++++++++++++++++++++.

LPDDR0_CTRL[0x0/4]= 0x3d04505;
LPDDR0_CTRL[0x3ac/4]= 0x340;
LPDDR0_CTRL[0x0/4]= 0x3d04505;
LPDDR0_CTRL[0x74/4]= 0x10100;
LPDDR0_CTRL[0x74/4]= 0x10000;
LPDDR0_PHY[0x84/4]= 0x3592f;
LPDDR0_PHY[0x1c4/4]= 0x67aa;
LPDDR0_PHY[0xc4/4]= 0x30004;
LPDDR0_PHY[0x400/4]= 0x380800a0;
LPDDR0_PHY[0x700/4]= 0x380800a0;
LPDDR0_PHY[0xa00/4]= 0x380800a0;
LPDDR0_PHY[0xd00/4]= 0x380800a0;
LPDDR0_PHY[0x9c/4]= 0x350000;
LPDDR0_PHY[0xa0/4]= 0x1000000;
LPDDR0_PHY[0x4/4]= 0x8e38;
LPDDR0_PHY[0x4/4]= 0x928e38;
//The write-leveling training enable signal. High is valid.
//0xe = rank0
LPDDR0_PHY[0x4/4]= 0x928e78;
//bit 24- write-leveling finish


while((LPDDR0_PHY[0x20c/4] & 0x1000000) == 0);

//wl_done_byte[3:0] - [15:12]


//exit write leveling

LPDDR0_PHY[0x4/4]= 0x928e38;
LPDDR0_PHY[0x4/4]= 0x928038;
LPDDR0_PHY[0xa8/4]= 0xaf19880;
LPDDR0_PHY[0x9c/4]= 0x350000;
LPDDR0_PHY[0xa0/4]= 0x1000000;
LPDDR0_PHY[0x4/4]= 0x928d38;
LPDDR0_PHY[0x4/4]= 0x928d38;
//d=rank1
LPDDR0_PHY[0x4/4]= 0x928d78;

while((LPDDR0_PHY[0x20c/4] & 0x1000000) == 0);

LPDDR0_PHY[0x4/4]= 0x928d38;
LPDDR0_PHY[0x4/4]= 0x928038;
LPDDR0_PHY[0xa8/4]= 0xaf19880;
LPDDR0_PHY[0x2f8/4]= 0xc00a0;
LPDDR0_PHY[0x400/4]= 0x3a0800a0;
LPDDR0_PHY[0x700/4]= 0x3a0800a0;
LPDDR0_PHY[0xa00/4]= 0x3a0800a0;
LPDDR0_PHY[0xd00/4]= 0x3a0800a0;
LPDDR0_PHY[0x400/4]= 0x3a080080;
LPDDR0_PHY[0x400/4]= 0x3a0800c0;
LPDDR0_PHY[0x700/4]= 0x3a080080;
LPDDR0_PHY[0x700/4]= 0x3a0800c0;
LPDDR0_PHY[0xa00/4]= 0x3a080080;
LPDDR0_PHY[0xa00/4]= 0x3a0800c0;
LPDDR0_PHY[0xd00/4]= 0x3a080080;
LPDDR0_PHY[0xd00/4]= 0x3a0800c0;
LPDDR0_PHY[0x94/4]= 0x0;
LPDDR0_PHY[0x44/4]= 0x300120;
LPDDR0_PHY[0x4/4]= 0x928038;
LPDDR0_PHY[0x4/4]= 0x928039;
//bit[11],The rx dqs calib complete signal
while((LPDDR0_PHY[0x20c/4] & 0x800) == 0);


LPDDR0_PHY[0x4/4]= 0x928038;
LPDDR0_PHY[0x4/4]= 0x928030;
LPDDR0_PHY[0x94/4]= 0x0;
LPDDR0_PHY[0x44/4]= 0x300120;
LPDDR0_PHY[0x4/4]= 0x928034;
//The auto rx-dqs calibration training enable signal.
LPDDR0_PHY[0x4/4]= 0x928035;

//bit[11]
while((LPDDR0_PHY[0x20c/4] & 0x800) == 0);


LPDDR0_PHY[0x4/4]= 0x928034;
LPDDR0_PHY[0x4/4]= 0x928030;
LPDDR0_PHY[0x94/4]= 0x20000000;
LPDDR0_PHY[0xb0/4]= 0x5555555;
LPDDR0_PHY[0x94/4]= 0x20000e00;
LPDDR0_PHY[0xa8/4]= 0xaf19881;
LPDDR0_PHY[0x94/4]= 0x20000e00;

//byte remap
//LPDDR0_PHY[0x464/4]= 0x9600;
//LPDDR0_PHY[0x764/4]= 0x1500;
//LPDDR0_PHY[0xa64/4]= 0x6300;
//LPDDR0_PHY[0x764/4]= 0x4b00;

//LPDDR0_PHY[0x464/4]= 0x9900;
//LPDDR0_PHY[0x764/4]= 0xde00;
//LPDDR0_PHY[0xa64/4]= 0xe400;
//LPDDR0_PHY[0x764/4]= 0xd200;


//LPDDR0_PHY[0x464/4]= 0xcc00;
//LPDDR0_PHY[0x764/4]= 0x8b00;
//LPDDR0_PHY[0xa64/4]= 0xb100;
//LPDDR0_PHY[0x764/4]= 0x8700;


//1: Enable the auto train of the read train.
LPDDR0_PHY[0x94/4]= 0x20000e01;

//bit[0]-train_true_done
//The complete signal of the read training(mpr/mpc mode). Active high.
while((LPDDR0_PHY[0x1f0/4] & 0x1) == 0);


READ_DATA = LPDDR0_PHY[0x2a4/4] ;

//reg_train_done_for_rd_to_reg[13:10]
//reg_train_error_for_rd_byte [3:0]


LPDDR0_PHY[0x94/4]= 0x20000e00;
LPDDR0_PHY[0x94/4]= 0x20000e00;
LPDDR0_PHY[0x94/4]= 0x20000000;
LPDDR0_PHY[0xa8/4]= 0xaf19880;
LPDDR0_PHY[0x430/4]= 0x18080000;
LPDDR0_PHY[0x430/4]= 0x18088000;
LPDDR0_PHY[0x430/4]= 0x18090000;
LPDDR0_PHY[0x430/4]= 0x18098000;
LPDDR0_PHY[0x430/4]= 0x180a0000;
LPDDR0_PHY[0x430/4]= 0x180a8000;
LPDDR0_PHY[0x430/4]= 0x180b0000;
LPDDR0_PHY[0x430/4]= 0x180b8000;
LPDDR0_PHY[0x430/4]= 0x180c0000;
LPDDR0_PHY[0x730/4]= 0x18080000;
LPDDR0_PHY[0x730/4]= 0x18088000;
LPDDR0_PHY[0x730/4]= 0x18090000;
LPDDR0_PHY[0x730/4]= 0x18098000;
LPDDR0_PHY[0x730/4]= 0x180a0000;
LPDDR0_PHY[0x730/4]= 0x180a8000;
LPDDR0_PHY[0x730/4]= 0x180b0000;
LPDDR0_PHY[0x730/4]= 0x180b8000;
LPDDR0_PHY[0x730/4]= 0x180c0000;
LPDDR0_PHY[0xa30/4]= 0x18080000;
LPDDR0_PHY[0xa30/4]= 0x18088000;
LPDDR0_PHY[0xa30/4]= 0x18090000;
LPDDR0_PHY[0xa30/4]= 0x18098000;
LPDDR0_PHY[0xa30/4]= 0x180a0000;
LPDDR0_PHY[0xa30/4]= 0x180a8000;
LPDDR0_PHY[0xa30/4]= 0x180b0000;
LPDDR0_PHY[0xa30/4]= 0x180b8000;
LPDDR0_PHY[0xa30/4]= 0x180c0000;
LPDDR0_PHY[0xd30/4]= 0x18080000;
LPDDR0_PHY[0xd30/4]= 0x18088000;
LPDDR0_PHY[0xd30/4]= 0x18090000;
LPDDR0_PHY[0xd30/4]= 0x18098000;
LPDDR0_PHY[0xd30/4]= 0x180a0000;
LPDDR0_PHY[0xd30/4]= 0x180a8000;
LPDDR0_PHY[0xd30/4]= 0x180b0000;
LPDDR0_PHY[0xd30/4]= 0x180b8000;
LPDDR0_PHY[0xd30/4]= 0x180c0000;
LPDDR0_PHY[0x94/4]= 0x20000000;
LPDDR0_PHY[0xb0/4]= 0x5555555;
LPDDR0_PHY[0x94/4]= 0x20000d00;
LPDDR0_PHY[0xa8/4]= 0xaf19881;
LPDDR0_PHY[0x94/4]= 0x20000d00;
LPDDR0_PHY[0x94/4]= 0x20000d01;



//bit[0]
while((LPDDR0_PHY[0x1f0/4] & 0x1) == 0);

READ_DATA = LPDDR0_PHY[0x2a4/4] ;


//////////////////bypass read training/////////////////
//LPDDR0_PHY[0x94/4]= 0x20000e00;

//////////////////bypass read training/////////////////


LPDDR0_PHY[0x94/4]= 0x20000d00;
LPDDR0_PHY[0x94/4]= 0x20000d00;
LPDDR0_PHY[0x94/4]= 0x20000000;
LPDDR0_PHY[0xa8/4]= 0xaf19880;
LPDDR0_PHY[0x430/4]= 0x180c4000;
LPDDR0_PHY[0x430/4]= 0x180c4400;
LPDDR0_PHY[0x430/4]= 0x180c4800;
LPDDR0_PHY[0x430/4]= 0x180c4c00;
LPDDR0_PHY[0x430/4]= 0x180c5000;
LPDDR0_PHY[0x430/4]= 0x180c5400;
LPDDR0_PHY[0x430/4]= 0x180c5800;
LPDDR0_PHY[0x430/4]= 0x180c5c00;
LPDDR0_PHY[0x430/4]= 0x180c6000;
LPDDR0_PHY[0x730/4]= 0x180c4000;
LPDDR0_PHY[0x730/4]= 0x180c4400;
LPDDR0_PHY[0x730/4]= 0x180c4800;
LPDDR0_PHY[0x730/4]= 0x180c4c00;
LPDDR0_PHY[0x730/4]= 0x180c5000;
LPDDR0_PHY[0x730/4]= 0x180c5400;
LPDDR0_PHY[0x730/4]= 0x180c5800;
LPDDR0_PHY[0x730/4]= 0x180c5c00;
LPDDR0_PHY[0x730/4]= 0x180c6000;
LPDDR0_PHY[0xa30/4]= 0x180c4000;
LPDDR0_PHY[0xa30/4]= 0x180c4400;
LPDDR0_PHY[0xa30/4]= 0x180c4800;
LPDDR0_PHY[0xa30/4]= 0x180c4c00;
LPDDR0_PHY[0xa30/4]= 0x180c5000;
LPDDR0_PHY[0xa30/4]= 0x180c5400;
LPDDR0_PHY[0xa30/4]= 0x180c5800;
LPDDR0_PHY[0xa30/4]= 0x180c5c00;
LPDDR0_PHY[0xa30/4]= 0x180c6000;
LPDDR0_PHY[0xd30/4]= 0x180c4000;
LPDDR0_PHY[0xd30/4]= 0x180c4400;
LPDDR0_PHY[0xd30/4]= 0x180c4800;
LPDDR0_PHY[0xd30/4]= 0x180c4c00;
LPDDR0_PHY[0xd30/4]= 0x180c5000;
LPDDR0_PHY[0xd30/4]= 0x180c5400;
LPDDR0_PHY[0xd30/4]= 0x180c5800;
LPDDR0_PHY[0xd30/4]= 0x180c5c00;
LPDDR0_PHY[0xd30/4]= 0x180c6000;
LPDDR0_PHY[0x468/4]= 0x80080;
LPDDR0_PHY[0x768/4]= 0x80080;
LPDDR0_PHY[0xa68/4]= 0x80080;
LPDDR0_PHY[0xd68/4]= 0x80080;
LPDDR0_PHY[0xa0/4]= 0x5000000;
LPDDR0_PHY[0x468/4]= 0xff880;
LPDDR0_PHY[0x768/4]= 0xff880;
LPDDR0_PHY[0xa68/4]= 0xff880;
LPDDR0_PHY[0xd68/4]= 0xff880;
LPDDR0_PHY[0xa0/4]= 0x7000000;
LPDDR0_PHY[0xa0/4]= 0x7000000;
LPDDR0_PHY[0x1bc/4]= 0x2b5f3892;
LPDDR0_PHY[0x1bc/4]= 0x2b5f3892;
LPDDR0_PHY[0x1bc/4]= 0x2b5f3892;
LPDDR0_PHY[0x1bc/4]= 0x2b5f3892;
LPDDR0_PHY[0x1c0/4]= 0xadbdb174;
LPDDR0_PHY[0x1c0/4]= 0xadbdb174;
LPDDR0_PHY[0x1c0/4]= 0xadbdb174;
LPDDR0_PHY[0x1c0/4]= 0xadbdb174;
LPDDR0_PHY[0x1c4/4]= 0x67aa;
LPDDR0_PHY[0x1c4/4]= 0x67aa;
LPDDR0_PHY[0x2f0/4]= 0x3f100cc5;
LPDDR0_PHY[0x2f0/4]= 0x3f100cc5;
LPDDR0_PHY[0x2f0/4]= 0x3f100cc5;
LPDDR0_PHY[0x2f0/4]= 0x3f100cc5;
LPDDR0_PHY[0x2f4/4]= 0x13cd;
LPDDR0_PHY[0x2f4/4]= 0x13cd;
LPDDR0_PHY[0x150/4]= 0x2b5f3892;
LPDDR0_PHY[0x150/4]= 0x2b5f3892;
LPDDR0_PHY[0x150/4]= 0x2b5f3892;
LPDDR0_PHY[0x150/4]= 0x2b5f3892;
LPDDR0_PHY[0x154/4]= 0xadbdb174;
LPDDR0_PHY[0x154/4]= 0xadbdb174;
LPDDR0_PHY[0x154/4]= 0xadbdb174;
LPDDR0_PHY[0x154/4]= 0xadbdb174;
LPDDR0_PHY[0x158/4]= 0x67aa;
LPDDR0_PHY[0x158/4]= 0x67aa;
LPDDR0_PHY[0x2c0/4]= 0x3f100cc5;
LPDDR0_PHY[0x2c0/4]= 0x3f100cc5;
LPDDR0_PHY[0x2c0/4]= 0x3f100cc5;
LPDDR0_PHY[0x2c0/4]= 0x3f100cc5;
LPDDR0_PHY[0x2c4/4]= 0x13cde148;
LPDDR0_PHY[0x2c4/4]= 0x13cde148;
LPDDR0_PHY[0x15c/4]= 0x3b53fd81;
LPDDR0_PHY[0x15c/4]= 0x3b53fd81;
LPDDR0_PHY[0x15c/4]= 0x3b53fd81;
LPDDR0_PHY[0x15c/4]= 0x3b53fd81;
LPDDR0_PHY[0x160/4]= 0x60289e68;
LPDDR0_PHY[0x160/4]= 0x60289e68;
LPDDR0_PHY[0x160/4]= 0x60289e68;
LPDDR0_PHY[0x160/4]= 0x60289e68;
LPDDR0_PHY[0x164/4]= 0xae7c;
LPDDR0_PHY[0x164/4]= 0xae7c;
LPDDR0_PHY[0x2c4/4]= 0x13cde148;
LPDDR0_PHY[0x2c4/4]= 0x13cde148;
LPDDR0_PHY[0x2c8/4]= 0xb6f6c6d2;
LPDDR0_PHY[0x2c8/4]= 0xb6f6c6d2;
LPDDR0_PHY[0x2c8/4]= 0xb6f6c6d2;
LPDDR0_PHY[0x2c8/4]= 0xb6f6c6d2;
LPDDR0_PHY[0x168/4]= 0x20188a27;
LPDDR0_PHY[0x168/4]= 0x20188a27;
LPDDR0_PHY[0x168/4]= 0x20188a27;
LPDDR0_PHY[0x168/4]= 0x20188a27;
LPDDR0_PHY[0x16c/4]= 0x9a2b5f38;
LPDDR0_PHY[0x16c/4]= 0x9a2b5f38;
LPDDR0_PHY[0x16c/4]= 0x9a2b5f38;
LPDDR0_PHY[0x16c/4]= 0x9a2b5f38;
LPDDR0_PHY[0x170/4]= 0x92ad;
LPDDR0_PHY[0x170/4]= 0x92ad;
LPDDR0_PHY[0x2cc/4]= 0xbdb17467;
LPDDR0_PHY[0x2cc/4]= 0xbdb17467;
LPDDR0_PHY[0x2cc/4]= 0xbdb17467;
LPDDR0_PHY[0x2cc/4]= 0xbdb17467;
LPDDR0_PHY[0x2d0/4]= 0xaa3fc291;
LPDDR0_PHY[0x2d0/4]= 0xaa3fc291;
LPDDR0_PHY[0x174/4]= 0x77a6fa03;
LPDDR0_PHY[0x174/4]= 0x77a6fa03;
LPDDR0_PHY[0x174/4]= 0x77a6fa03;
LPDDR0_PHY[0x174/4]= 0x77a6fa03;
LPDDR0_PHY[0x178/4]= 0xc1503cd1;
LPDDR0_PHY[0x178/4]= 0xc1503cd1;
LPDDR0_PHY[0x178/4]= 0xc1503cd1;
LPDDR0_PHY[0x178/4]= 0xc1503cd1;
LPDDR0_PHY[0x17c/4]= 0x5cf9;
LPDDR0_PHY[0x17c/4]= 0x5cf9;
LPDDR0_PHY[0x2d0/4]= 0xaa3fc291;
LPDDR0_PHY[0x2d0/4]= 0xaa3fc291;
LPDDR0_PHY[0x2d4/4]= 0x6ced8da5;
LPDDR0_PHY[0x2d4/4]= 0x6ced8da5;
LPDDR0_PHY[0x2d4/4]= 0x6ced8da5;
LPDDR0_PHY[0x2d4/4]= 0x6ced8da5;
LPDDR0_PHY[0x180/4]= 0x5b7b63e9;
LPDDR0_PHY[0x180/4]= 0x5b7b63e9;
LPDDR0_PHY[0x180/4]= 0x5b7b63e9;
LPDDR0_PHY[0x180/4]= 0x5b7b63e9;
LPDDR0_PHY[0x184/4]= 0xce547f20;
LPDDR0_PHY[0x184/4]= 0xce547f20;
LPDDR0_PHY[0x184/4]= 0xce547f20;
LPDDR0_PHY[0x184/4]= 0xce547f20;
LPDDR0_PHY[0x188/4]= 0x188a;
LPDDR0_PHY[0x188/4]= 0x188a;
LPDDR0_PHY[0x2d8/4]= 0x279a2b5f;
LPDDR0_PHY[0x2d8/4]= 0x279a2b5f;
LPDDR0_PHY[0x2d8/4]= 0x279a2b5f;
LPDDR0_PHY[0x2d8/4]= 0x279a2b5f;
LPDDR0_PHY[0x2dc/4]= 0x38923892;
LPDDR0_PHY[0x2dc/4]= 0x38923892;
LPDDR0_PHY[0x18c/4]= 0xce547f20;
LPDDR0_PHY[0x18c/4]= 0xce547f20;
LPDDR0_PHY[0x18c/4]= 0xce547f20;
LPDDR0_PHY[0x18c/4]= 0xce547f20;
LPDDR0_PHY[0x190/4]= 0x188a279a;
LPDDR0_PHY[0x190/4]= 0x188a279a;
LPDDR0_PHY[0x190/4]= 0x188a279a;
LPDDR0_PHY[0x190/4]= 0x188a279a;
LPDDR0_PHY[0x194/4]= 0x2b5f;
LPDDR0_PHY[0x194/4]= 0x2b5f;
LPDDR0_PHY[0x2dc/4]= 0x38923892;
LPDDR0_PHY[0x2dc/4]= 0x38923892;
LPDDR0_PHY[0x2e0/4]= 0xadbdb174;
LPDDR0_PHY[0x2e0/4]= 0xadbdb174;
LPDDR0_PHY[0x2e0/4]= 0xadbdb174;
LPDDR0_PHY[0x2e0/4]= 0xadbdb174;
LPDDR0_PHY[0x198/4]= 0xd6de58ba;
LPDDR0_PHY[0x198/4]= 0xd6de58ba;
LPDDR0_PHY[0x198/4]= 0xd6de58ba;
LPDDR0_PHY[0x198/4]= 0xd6de58ba;
LPDDR0_PHY[0x19c/4]= 0x33d51f08;
LPDDR0_PHY[0x19c/4]= 0x33d51f08;
LPDDR0_PHY[0x19c/4]= 0x33d51f08;
LPDDR0_PHY[0x19c/4]= 0x33d51f08;
LPDDR0_PHY[0x1a0/4]= 0x86e2;
LPDDR0_PHY[0x1a0/4]= 0x86e2;
LPDDR0_PHY[0x2e4/4]= 0x89e6ca17;
LPDDR0_PHY[0x2e4/4]= 0x89e6ca17;
LPDDR0_PHY[0x2e4/4]= 0x89e6ca17;
LPDDR0_PHY[0x2e4/4]= 0x89e6ca17;
LPDDR0_PHY[0x2e8/4]= 0x8e641b4b;
LPDDR0_PHY[0x2e8/4]= 0x8e641b4b;
LPDDR0_PHY[0x1a4/4]= 0x82a178a2;
LPDDR0_PHY[0x1a4/4]= 0x82a178a2;
LPDDR0_PHY[0x1a4/4]= 0x82a178a2;
LPDDR0_PHY[0x1a4/4]= 0x82a178a2;
LPDDR0_PHY[0x1a8/4]= 0xb9f28523;
LPDDR0_PHY[0x1a8/4]= 0xb9f28523;
LPDDR0_PHY[0x1a8/4]= 0xb9f28523;
LPDDR0_PHY[0x1a8/4]= 0xb9f28523;
LPDDR0_PHY[0x1ac/4]= 0x1d9da;
LPDDR0_PHY[0x1ac/4]= 0x1d9da;
LPDDR0_PHY[0x2e8/4]= 0x8e641b4b;
LPDDR0_PHY[0x2e8/4]= 0x8e641b4b;
LPDDR0_PHY[0x2ec/4]= 0x77a6fa03;
LPDDR0_PHY[0x2ec/4]= 0x77a6fa03;
LPDDR0_PHY[0x2ec/4]= 0x77a6fa03;
LPDDR0_PHY[0x2ec/4]= 0x77a6fa03;
LPDDR0_PHY[0xa0/4]= 0x7000380;
LPDDR0_PHY[0xa8/4]= 0xaf19881;
LPDDR0_PHY[0xa0/4]= 0x7000382;
LPDDR0_PHY[0xa0/4]= 0x7000382;
LPDDR0_PHY[0x1c4/4]= 0x67aa;
LPDDR0_PHY[0xa0/4]= 0x17000382;
//dm read train enable:
LPDDR0_PHY[0x1c4/4]= 0x80067aa;

//bit[6]

//bit6-train_step1_delay_done
while((LPDDR0_PHY[0x1f0/4] & 0x40) == 0);

//bit[7]-train_all_step_done


while((LPDDR0_PHY[0x1f0/4] & 0x80) == 0);


READ_DATA = LPDDR0_PHY[0x1f0/4];
READ_DATA = LPDDR0_PHY[0x1f0/4];
READ_DATA = LPDDR0_PHY[0x1f0/4];




LPDDR0_PHY[0xa0/4]= 0x17000380;
LPDDR0_PHY[0xa0/4]= 0x17000380;
LPDDR0_PHY[0xa0/4]= 0x17000000;
LPDDR0_PHY[0xa8/4]= 0xaf19880;
LPDDR0_PHY[0xa0/4]= 0x17000000;
LPDDR0_PHY[0x1bc/4]= 0x2b5f3892;
LPDDR0_PHY[0x1bc/4]= 0x2b5f3892;
LPDDR0_PHY[0x1bc/4]= 0x2b5f3892;
LPDDR0_PHY[0x1bc/4]= 0x2b5f3892;
LPDDR0_PHY[0x1c0/4]= 0xadbdb174;
LPDDR0_PHY[0x1c0/4]= 0xadbdb174;
LPDDR0_PHY[0x1c0/4]= 0xadbdb174;
LPDDR0_PHY[0x1c0/4]= 0xadbdb174;
LPDDR0_PHY[0x1c4/4]= 0x80067aa;
LPDDR0_PHY[0x1c4/4]= 0x80067aa;
LPDDR0_PHY[0x2f0/4]= 0x3f100cc5;
LPDDR0_PHY[0x2f0/4]= 0x3f100cc5;
LPDDR0_PHY[0x2f0/4]= 0x3f100cc5;
LPDDR0_PHY[0x2f0/4]= 0x3f100cc5;
LPDDR0_PHY[0x2f4/4]= 0x13cd;
LPDDR0_PHY[0x2f4/4]= 0x13cd;
LPDDR0_PHY[0x150/4]= 0x2b5f3892;
LPDDR0_PHY[0x150/4]= 0x2b5f3892;
LPDDR0_PHY[0x150/4]= 0x2b5f3892;
LPDDR0_PHY[0x150/4]= 0x2b5f3892;
LPDDR0_PHY[0x154/4]= 0xadbdb174;
LPDDR0_PHY[0x154/4]= 0xadbdb174;
LPDDR0_PHY[0x154/4]= 0xadbdb174;
LPDDR0_PHY[0x154/4]= 0xadbdb174;
LPDDR0_PHY[0x158/4]= 0x67aa;
LPDDR0_PHY[0x158/4]= 0x67aa;
LPDDR0_PHY[0x2c0/4]= 0x3f100cc5;
LPDDR0_PHY[0x2c0/4]= 0x3f100cc5;
LPDDR0_PHY[0x2c0/4]= 0x3f100cc5;
LPDDR0_PHY[0x2c0/4]= 0x3f100cc5;
LPDDR0_PHY[0x2c4/4]= 0x13cde148;
LPDDR0_PHY[0x2c4/4]= 0x13cde148;
LPDDR0_PHY[0x15c/4]= 0x3b53fd81;
LPDDR0_PHY[0x15c/4]= 0x3b53fd81;
LPDDR0_PHY[0x15c/4]= 0x3b53fd81;
LPDDR0_PHY[0x15c/4]= 0x3b53fd81;
LPDDR0_PHY[0x160/4]= 0x60289e68;
LPDDR0_PHY[0x160/4]= 0x60289e68;
LPDDR0_PHY[0x160/4]= 0x60289e68;
LPDDR0_PHY[0x160/4]= 0x60289e68;
LPDDR0_PHY[0x164/4]= 0xae7c;
LPDDR0_PHY[0x164/4]= 0xae7c;
LPDDR0_PHY[0x2c4/4]= 0x13cde148;
LPDDR0_PHY[0x2c4/4]= 0x13cde148;
LPDDR0_PHY[0x2c8/4]= 0xb6f6c6d2;
LPDDR0_PHY[0x2c8/4]= 0xb6f6c6d2;
LPDDR0_PHY[0x2c8/4]= 0xb6f6c6d2;
LPDDR0_PHY[0x2c8/4]= 0xb6f6c6d2;
LPDDR0_PHY[0x168/4]= 0x20188a27;
LPDDR0_PHY[0x168/4]= 0x20188a27;
LPDDR0_PHY[0x168/4]= 0x20188a27;
LPDDR0_PHY[0x168/4]= 0x20188a27;
LPDDR0_PHY[0x16c/4]= 0x9a2b5f38;
LPDDR0_PHY[0x16c/4]= 0x9a2b5f38;
LPDDR0_PHY[0x16c/4]= 0x9a2b5f38;
LPDDR0_PHY[0x16c/4]= 0x9a2b5f38;
LPDDR0_PHY[0x170/4]= 0x92ad;
LPDDR0_PHY[0x170/4]= 0x92ad;
LPDDR0_PHY[0x2cc/4]= 0xbdb17467;
LPDDR0_PHY[0x2cc/4]= 0xbdb17467;
LPDDR0_PHY[0x2cc/4]= 0xbdb17467;
LPDDR0_PHY[0x2cc/4]= 0xbdb17467;
LPDDR0_PHY[0x2d0/4]= 0xaa3fc291;
LPDDR0_PHY[0x2d0/4]= 0xaa3fc291;
LPDDR0_PHY[0x174/4]= 0x77a6fa03;
LPDDR0_PHY[0x174/4]= 0x77a6fa03;
LPDDR0_PHY[0x174/4]= 0x77a6fa03;
LPDDR0_PHY[0x174/4]= 0x77a6fa03;
LPDDR0_PHY[0x178/4]= 0xc1503cd1;
LPDDR0_PHY[0x178/4]= 0xc1503cd1;
LPDDR0_PHY[0x178/4]= 0xc1503cd1;
LPDDR0_PHY[0x178/4]= 0xc1503cd1;
LPDDR0_PHY[0x17c/4]= 0x5cf9;
LPDDR0_PHY[0x17c/4]= 0x5cf9;
LPDDR0_PHY[0x2d0/4]= 0xaa3fc291;
LPDDR0_PHY[0x2d0/4]= 0xaa3fc291;
LPDDR0_PHY[0x2d4/4]= 0x6ced8da5;
LPDDR0_PHY[0x2d4/4]= 0x6ced8da5;
LPDDR0_PHY[0x2d4/4]= 0x6ced8da5;
LPDDR0_PHY[0x2d4/4]= 0x6ced8da5;
LPDDR0_PHY[0x180/4]= 0x5b7b63e9;
LPDDR0_PHY[0x180/4]= 0x5b7b63e9;
LPDDR0_PHY[0x180/4]= 0x5b7b63e9;
LPDDR0_PHY[0x180/4]= 0x5b7b63e9;
LPDDR0_PHY[0x184/4]= 0xce547f20;
LPDDR0_PHY[0x184/4]= 0xce547f20;
LPDDR0_PHY[0x184/4]= 0xce547f20;
LPDDR0_PHY[0x184/4]= 0xce547f20;
LPDDR0_PHY[0x188/4]= 0x188a;
LPDDR0_PHY[0x188/4]= 0x188a;
LPDDR0_PHY[0x2d8/4]= 0x279a2b5f;
LPDDR0_PHY[0x2d8/4]= 0x279a2b5f;
LPDDR0_PHY[0x2d8/4]= 0x279a2b5f;
LPDDR0_PHY[0x2d8/4]= 0x279a2b5f;
LPDDR0_PHY[0x2dc/4]= 0x38923892;
LPDDR0_PHY[0x2dc/4]= 0x38923892;
LPDDR0_PHY[0x18c/4]= 0xce547f20;
LPDDR0_PHY[0x18c/4]= 0xce547f20;
LPDDR0_PHY[0x18c/4]= 0xce547f20;
LPDDR0_PHY[0x18c/4]= 0xce547f20;
LPDDR0_PHY[0x190/4]= 0x188a279a;
LPDDR0_PHY[0x190/4]= 0x188a279a;
LPDDR0_PHY[0x190/4]= 0x188a279a;
LPDDR0_PHY[0x190/4]= 0x188a279a;
LPDDR0_PHY[0x194/4]= 0x2b5f;
LPDDR0_PHY[0x194/4]= 0x2b5f;
LPDDR0_PHY[0x2dc/4]= 0x38923892;
LPDDR0_PHY[0x2dc/4]= 0x38923892;
LPDDR0_PHY[0x2e0/4]= 0xadbdb174;
LPDDR0_PHY[0x2e0/4]= 0xadbdb174;
LPDDR0_PHY[0x2e0/4]= 0xadbdb174;
LPDDR0_PHY[0x2e0/4]= 0xadbdb174;
LPDDR0_PHY[0x198/4]= 0xd6de58ba;
LPDDR0_PHY[0x198/4]= 0xd6de58ba;
LPDDR0_PHY[0x198/4]= 0xd6de58ba;
LPDDR0_PHY[0x198/4]= 0xd6de58ba;
LPDDR0_PHY[0x19c/4]= 0x33d51f08;
LPDDR0_PHY[0x19c/4]= 0x33d51f08;
LPDDR0_PHY[0x19c/4]= 0x33d51f08;
LPDDR0_PHY[0x19c/4]= 0x33d51f08;
LPDDR0_PHY[0x1a0/4]= 0x86e2;
LPDDR0_PHY[0x1a0/4]= 0x86e2;
LPDDR0_PHY[0x2e4/4]= 0x89e6ca17;
LPDDR0_PHY[0x2e4/4]= 0x89e6ca17;
LPDDR0_PHY[0x2e4/4]= 0x89e6ca17;
LPDDR0_PHY[0x2e4/4]= 0x89e6ca17;
LPDDR0_PHY[0x2e8/4]= 0x8e641b4b;
LPDDR0_PHY[0x2e8/4]= 0x8e641b4b;
LPDDR0_PHY[0x1a4/4]= 0x82a178a2;
LPDDR0_PHY[0x1a4/4]= 0x82a178a2;
LPDDR0_PHY[0x1a4/4]= 0x82a178a2;
LPDDR0_PHY[0x1a4/4]= 0x82a178a2;
LPDDR0_PHY[0x1a8/4]= 0xb9f28523;
LPDDR0_PHY[0x1a8/4]= 0xb9f28523;
LPDDR0_PHY[0x1a8/4]= 0xb9f28523;
LPDDR0_PHY[0x1a8/4]= 0xb9f28523;
LPDDR0_PHY[0x1ac/4]= 0x1d9da;
LPDDR0_PHY[0x1ac/4]= 0x1d9da;
LPDDR0_PHY[0x2e8/4]= 0x8e641b4b;
LPDDR0_PHY[0x2e8/4]= 0x8e641b4b;
LPDDR0_PHY[0x2ec/4]= 0x77a6fa03;
LPDDR0_PHY[0x2ec/4]= 0x77a6fa03;
LPDDR0_PHY[0x2ec/4]= 0x77a6fa03;
LPDDR0_PHY[0x2ec/4]= 0x77a6fa03;
LPDDR0_PHY[0xa0/4]= 0x17000340;
LPDDR0_PHY[0xa8/4]= 0xaf19881;
LPDDR0_PHY[0xa0/4]= 0x17000342;
LPDDR0_PHY[0xa0/4]= 0x7000342;
LPDDR0_PHY[0x1c4/4]= 0x67aa;
LPDDR0_PHY[0xa0/4]= 0x17000342;
LPDDR0_PHY[0x1c4/4]= 0x80067aa;

//bit[6]
while((LPDDR0_PHY[0x1f0/4] & 0x40) == 0);
//bit[7]
while((LPDDR0_PHY[0x1f0/4] & 0x80) == 0);

READ_DATA = LPDDR0_PHY[0x1f0/4];
READ_DATA = LPDDR0_PHY[0x1f0/4];
READ_DATA = LPDDR0_PHY[0x1f0/4];


LPDDR0_PHY[0xa0/4]= 0x17000340;
LPDDR0_PHY[0xa0/4]= 0x17000340;
LPDDR0_PHY[0xa0/4]= 0x17000000;

//printf("aa PHY: 0x%08x\n",LPDDR0_PHY[0x1f0/4]);

LPDDR0_PHY[0xa8/4]= 0xaf19880;

//printf("aa PHY: 0x%08x\n",LPDDR0_PHY[0x1f0/4]);

LPDDR0_CTRL[0x0/4]= 0x3c04505;
LPDDR0_CTRL[0x2e8/4]= 0x30202;
LPDDR0_CTRL[0x2e8/4]= 0x400202;
LPDDR0_CTRL[0x5a0/4]= 0x600;
LPDDR0_CTRL[0x5a0/4]= 0x637;
LPDDR0_CTRL[0x2e8/4]= 0x400212;
LPDDR0_CTRL[0x2e8/4]= 0x400202;
LPDDR0_CTRL[0x598/4]= 0x2008;
LPDDR0_CTRL[0x3ac/4]= 0x340;
LPDDR0_CTRL[0xa0/4]= 0x2000d00;
LPDDR0_CTRL[0xc0/4]= 0x2000d00;
LPDDR0_CTRL[0x120/4]= 0x11;
LPDDR0_CTRL[0x120/4]= 0x1;

APB[0x0/4] = 0x2c00000;

//printf("aa PHY: 0x%08x\n",LPDDR0_PHY[0x1f0/4]);


////////////////LPDDR1///////////////////////

LPDDR1_CTRL[0x270/4]= 0x48fa;
LPDDR1_CTRL[0x270/4]= 0x491a;
LPDDR1_CTRL[0x270/4]= 0x471a;
LPDDR1_CTRL[0x270/4]= 0x471a;
LPDDR1_CTRL[0x270/4]= 0x471a;
LPDDR1_CTRL[0x274/4]= 0x3020100;
LPDDR1_CTRL[0x274/4]= 0x3020100;
LPDDR1_CTRL[0x274/4]= 0x3020100;
LPDDR1_CTRL[0x274/4]= 0x3020100;
LPDDR1_CTRL[0x278/4]= 0x7060504;
LPDDR1_CTRL[0x278/4]= 0x7060504;
LPDDR1_CTRL[0x278/4]= 0x70a0504;
LPDDR1_CTRL[0x278/4]= 0xb0a0504;
LPDDR1_CTRL[0x27c/4]= 0x90c;
LPDDR1_CTRL[0x27c/4]= 0x90c;
LPDDR1_CTRL[0x27c/4]= 0x90c;
LPDDR1_CTRL[0x27c/4]= 0x90c;
LPDDR1_CTRL[0x280/4]= 0xd0c0b0d;
LPDDR1_CTRL[0x280/4]= 0xd0c0e0d;
LPDDR1_CTRL[0x280/4]= 0xd0f0e0d;
LPDDR1_CTRL[0x280/4]= 0x100f0e0d;
LPDDR1_CTRL[0x284/4]= 0x11100f11;
LPDDR1_CTRL[0x284/4]= 0x11101211;
LPDDR1_CTRL[0x284/4]= 0x11131211;
LPDDR1_CTRL[0x284/4]= 0x14131211;
LPDDR1_CTRL[0x288/4]= 0x15141315;
LPDDR1_CTRL[0x288/4]= 0x15141615;
LPDDR1_CTRL[0x288/4]= 0x15171615;
LPDDR1_CTRL[0x288/4]= 0x18171615;
LPDDR1_CTRL[0x28c/4]= 0x19181719;
LPDDR1_CTRL[0x28c/4]= 0x19181a19;
LPDDR1_CTRL[0x28c/4]= 0x191b1a19;
LPDDR1_CTRL[0x28c/4]= 0x1c1b1a19;
LPDDR1_CTRL[0x290/4]= 0x1d;
LPDDR1_CTRL[0x290/4]= 0x1d;
LPDDR1_CTRL[0x294/4]= 0x1c1b06;
LPDDR1_CTRL[0x294/4]= 0x1c0706;
LPDDR1_CTRL[0x294/4]= 0x80706;
LPDDR1_CTRL[0x294/4]= 0x80706;
LPDDR1_CTRL[0x298/4]= 0x1e1e;
LPDDR1_CTRL[0x298/4]= 0x1e;
LPDDR1_CTRL[0x2a4/4]= 0x268254;
LPDDR1_CTRL[0x2a4/4]= 0xb5028254;
LPDDR1_CTRL[0x2b0/4]= 0x1f8000;
LPDDR1_CTRL[0x2b0/4]= 0x1f0900;
LPDDR1_CTRL[0x2ac/4]= 0xc4425ab0;
LPDDR1_CTRL[0x64/4]= 0x0;
LPDDR1_CTRL[0x64/4]= 0xd6000000;
LPDDR1_CTRL[0x64/4]= 0xd6000000;
LPDDR1_CTRL[0x64/4]= 0xd6000000;
LPDDR1_CTRL[0x64/4]= 0xd6980000;
LPDDR1_CTRL[0x64/4]= 0xd6980001;
LPDDR1_CTRL[0x64/4]= 0xd698ae01;
LPDDR1_CTRL[0x2a0/4]= 0x3;
LPDDR1_CTRL[0x0/4]= 0x3fd04480;
LPDDR1_CTRL[0x2e4/4]= 0x1;
LPDDR1_CTRL[0x2e4/4]= 0x1;
LPDDR1_CTRL[0x124/4]= 0x0;
LPDDR1_CTRL[0x0/4]= 0x3fd04480;
LPDDR1_CTRL[0x70/4]= 0x0;
LPDDR1_CTRL[0x560/4]= 0x1ff;
LPDDR1_CTRL[0x178/4]= 0x80700;
LPDDR1_CTRL[0x0/4]= 0x3fd04500;
LPDDR1_CTRL[0x0/4]= 0x3fd04500;
LPDDR1_CTRL[0x0/4]= 0x3d04500;
LPDDR1_CTRL[0x160/4]= 0xff0503;
LPDDR1_CTRL[0x160/4]= 0xff0503;
LPDDR1_CTRL[0x0/4]= 0x3d04505;
LPDDR1_CTRL[0x2e4/4]= 0x0;
LPDDR1_CTRL[0x2e4/4]= 0xd300;
LPDDR1_CTRL[0x98/4]= 0x101f0000;
LPDDR1_CTRL[0x56c/4]= 0x20a;
LPDDR1_CTRL[0x2b8/4]= 0x10;
LPDDR1_CTRL[0x88/4]= 0x4040;
LPDDR1_CTRL[0x8c/4]= 0x308086c;
LPDDR1_CTRL[0x124/4]= 0x0;
LPDDR1_CTRL[0x70/4]= 0x0;
LPDDR1_CTRL[0x12c/4]= 0x0;
LPDDR1_CTRL[0x130/4]= 0x6fffffff;
LPDDR1_CTRL[0x180/4]= 0x10004080;
LPDDR1_CTRL[0x180/4]= 0x10004040;
LPDDR1_CTRL[0x90/4]= 0x8083100;
LPDDR1_CTRL[0x90/4]= 0x8083190;
LPDDR1_CTRL[0x90/4]= 0x8083190;
LPDDR1_CTRL[0x8c/4]= 0x373086c;
LPDDR1_CTRL[0x8c/4]= 0x373086c;
LPDDR1_CTRL[0x90/4]= 0x8633190;
LPDDR1_CTRL[0x90/4]= 0x6a633190;
LPDDR1_CTRL[0x140/4]= 0x1421232;
LPDDR1_CTRL[0x140/4]= 0x1420142;
LPDDR1_CTRL[0x160/4]= 0xff0503;
LPDDR1_CTRL[0x5a8/4]= 0xff001a;
LPDDR1_CTRL[0x164/4]= 0xff001a;
LPDDR1_CTRL[0x164/4]= 0xff001a;
LPDDR1_CTRL[0x5a8/4]= 0xff001a;
LPDDR1_CTRL[0x56c/4]= 0x20a;
LPDDR1_CTRL[0x564/4]= 0x4040510;
LPDDR1_CTRL[0x56c/4]= 0x20a;
LPDDR1_CTRL[0x564/4]= 0x8040510;
LPDDR1_CTRL[0x564/4]= 0x8040510;
LPDDR1_CTRL[0x56c/4]= 0x40a;
LPDDR1_CTRL[0x55c/4]= 0x80000000;
LPDDR1_CTRL[0x60/4]= 0x200203;
LPDDR1_CTRL[0x60/4]= 0x202203;
LPDDR1_CTRL[0x7c/4]= 0x20001;
LPDDR1_CTRL[0x2e8/4]= 0x30200;
LPDDR1_CTRL[0x59c/4]= 0x4000000;
LPDDR1_CTRL[0x59c/4]= 0x4003000;
LPDDR1_CTRL[0x59c/4]= 0x40a3000;
LPDDR1_CTRL[0x59c/4]= 0x40a3020;
LPDDR1_CTRL[0x598/4]= 0x2008;
LPDDR1_PHY[0x22c/4]= 0x20f06e;
LPDDR1_PHY[0x144/4]= 0x120000;
LPDDR1_PHY[0x2fc/4]= 0x7e00000;
LPDDR1_CTRL[0x58c/4]= 0x0;
LPDDR1_CTRL[0x168/4]= 0x3ff0ff80;
LPDDR1_CTRL[0x168/4]= 0x3ff08000;
LPDDR1_CTRL[0x530/4]= 0xffffff80;
LPDDR1_CTRL[0x530/4]= 0xfff07f80;
LPDDR1_CTRL[0x120/4]= 0x1;
LPDDR1_CTRL[0x2b4/4]= 0x41010;
LPDDR1_CTRL[0x55c/4]= 0x8000001c;
LPDDR1_CTRL[0x558/4]= 0x7;
LPDDR1_CTRL[0x554/4]= 0x3f;
LPDDR1_CTRL[0x40/4]= 0xf1f;
LPDDR1_CTRL[0x40/4]= 0x8d1f;
LPDDR1_CTRL[0x28/4]= 0x20040001;
LPDDR1_CTRL[0x38/4]= 0x160f0f0f;
LPDDR1_CTRL[0x18/4]= 0x80f0f0f;
LPDDR1_CTRL[0x38/4]= 0x16100f0f;
LPDDR1_CTRL[0x3c/4]= 0x2b0f0f0f;
LPDDR1_CTRL[0x38/4]= 0x16100f08;
LPDDR1_CTRL[0x3c/4]= 0x2b0f290f;
LPDDR1_CTRL[0x3c/4]= 0x2b22290f;
LPDDR1_CTRL[0x3c/4]= 0x2b222913;
LPDDR1_CTRL[0x570/4]= 0x51f;
LPDDR1_CTRL[0x4/4]= 0x11000f;
LPDDR1_CTRL[0x4/4]= 0x110010;
LPDDR1_CTRL[0x8/4]= 0x4f4;
LPDDR1_CTRL[0xc/4]= 0xf0024;
LPDDR1_CTRL[0x20/4]= 0x23e017;
LPDDR1_CTRL[0x34/4]= 0x1740f0f;
LPDDR1_CTRL[0xc/4]= 0x100024;
LPDDR1_CTRL[0x10/4]= 0xf0008;
LPDDR1_CTRL[0x10/4]= 0x80008;
LPDDR1_CTRL[0x28/4]= 0x20040001;
LPDDR1_CTRL[0x14/4]= 0xf150f0f;
LPDDR1_CTRL[0x14/4]= 0xf150a0f;
LPDDR1_CTRL[0x14/4]= 0xf150a08;
LPDDR1_CTRL[0x18/4]= 0x80b0f0f;
LPDDR1_CTRL[0x18/4]= 0x80b080f;
LPDDR1_CTRL[0x18/4]= 0x80b0808;
LPDDR1_CTRL[0x14/4]= 0x20150a08;
LPDDR1_CTRL[0x24/4]= 0x9050000;
LPDDR1_CTRL[0x2c/4]= 0x5000009;
LPDDR1_CTRL[0x30/4]= 0x1380200;
LPDDR1_CTRL[0x30/4]= 0x1380000;
LPDDR1_CTRL[0x34/4]= 0x174980f;
LPDDR1_CTRL[0x2c/4]= 0x3000009;
LPDDR1_CTRL[0x24/4]= 0x9080000;
LPDDR1_CTRL[0x178/4]= 0x140700;
LPDDR1_CTRL[0x178/4]= 0x140500;
LPDDR1_CTRL[0x178/4]= 0xe140500;
LPDDR1_CTRL[0x2c/4]= 0x3050009;
LPDDR1_CTRL[0x2b4/4]= 0x4c410;
LPDDR1_CTRL[0x50/4]= 0x3000000;
LPDDR1_CTRL[0x50/4]= 0x3001800;
LPDDR1_CTRL[0x1c/4]= 0x50000000;
LPDDR1_CTRL[0x1c/4]= 0x50000500;
LPDDR1_CTRL[0x1c/4]= 0x500c0500;
LPDDR1_CTRL[0x1c/4]= 0x500c0504;
LPDDR1_CTRL[0x38/4]= 0x16100a08;
LPDDR1_CTRL[0x2c/4]= 0x3051409;
LPDDR1_CTRL[0x28/4]= 0x20040010;
LPDDR1_CTRL[0x20/4]= 0x74a017;
LPDDR1_CTRL[0x24/4]= 0x9080064;
LPDDR1_CTRL[0x50/4]= 0x9c30d190;
LPDDR1_CTRL[0x80/4]= 0xc004000;
LPDDR1_CTRL[0x28/4]= 0x20040c10;
LPDDR1_CTRL[0x80/4]= 0xc004019;
LPDDR1_CTRL[0x9c/4]= 0x70c;
LPDDR1_CTRL[0x9c/4]= 0xc0c;
LPDDR1_CTRL[0x94/4]= 0x30f;
LPDDR1_CTRL[0x94/4]= 0x303;
LPDDR1_CTRL[0x2b4/4]= 0x4c400;
LPDDR1_CTRL[0x28/4]= 0x20040c10;
LPDDR1_CTRL[0x44/4]= 0x11000f;
LPDDR1_CTRL[0x44/4]= 0x11bbe5;
LPDDR1_CTRL[0x48/4]= 0x14000f;
LPDDR1_CTRL[0x48/4]= 0x140024;
LPDDR1_CTRL[0x4c/4]= 0xc000f;
LPDDR1_CTRL[0x4c/4]= 0xc000c;
LPDDR1_CTRL[0x2ec/4]= 0xd000000;
LPDDR1_CTRL[0x2ec/4]= 0xd000124;
LPDDR1_CTRL[0x2f0/4]= 0x2120000;
LPDDR1_CTRL[0x2f0/4]= 0x2120318;
LPDDR1_CTRL[0x2f4/4]= 0xb000000;
LPDDR1_CTRL[0x2f4/4]= 0xb000c4d;
LPDDR1_CTRL[0x2f8/4]= 0xe000000;
LPDDR1_CTRL[0x2f8/4]= 0xe001600;
LPDDR1_CTRL[0x2fc/4]= 0xd000000;
LPDDR1_CTRL[0x2fc/4]= 0xd000124;
LPDDR1_CTRL[0x300/4]= 0x2120000;
LPDDR1_CTRL[0x300/4]= 0x2120318;
LPDDR1_CTRL[0x304/4]= 0xb000000;
LPDDR1_CTRL[0x304/4]= 0xb000c4d;
LPDDR1_CTRL[0x308/4]= 0xe000000;
LPDDR1_CTRL[0x308/4]= 0xe001600;
LPDDR1_CTRL[0x30c/4]= 0xd000000;
LPDDR1_CTRL[0x30c/4]= 0xd000124;
LPDDR1_CTRL[0x310/4]= 0x2120000;
LPDDR1_CTRL[0x310/4]= 0x2120318;
LPDDR1_CTRL[0x314/4]= 0xb000000;
LPDDR1_CTRL[0x314/4]= 0xb000c4d;
LPDDR1_CTRL[0x318/4]= 0xe000000;
LPDDR1_CTRL[0x318/4]= 0xe001600;
LPDDR1_CTRL[0x31c/4]= 0xd000000;
LPDDR1_CTRL[0x31c/4]= 0xd000124;
LPDDR1_CTRL[0x320/4]= 0x2120000;
LPDDR1_CTRL[0x320/4]= 0x2120318;
LPDDR1_CTRL[0x324/4]= 0xb000000;
LPDDR1_CTRL[0x324/4]= 0xb000c4d;
LPDDR1_CTRL[0x328/4]= 0xe000000;
LPDDR1_CTRL[0x328/4]= 0xe001600;
LPDDR1_PHY[0x0/4]= 0x60000f57;
LPDDR1_PHY[0x0/4]= 0x60000f57;
LPDDR1_PHY[0x20/4]= 0xe440;
LPDDR1_PHY[0x1c/4]= 0x10020013;
LPDDR1_PHY[0x48/4]= 0x3d00000;
LPDDR1_PHY[0xac/4]= 0x0;
LPDDR1_PHY[0xac/4]= 0x0;
LPDDR1_PHY[0xac/4]= 0x2000;
LPDDR1_PHY[0x48/4]= 0x3d00000;
LPDDR1_PHY[0xac/4]= 0x3000;
LPDDR1_PHY[0x48/4]= 0x3d00000;
LPDDR1_PHY[0x10/4]= 0x8000000;
LPDDR1_PHY[0xc/4]= 0xe060606;
LPDDR1_PHY[0x8/4]= 0x0;
LPDDR1_PHY[0xa8/4]= 0x25819880;
LPDDR1_PHY[0xa8/4]= 0xaf19880;
LPDDR1_PHY[0xdc/4]= 0x4901b080;
LPDDR1_PHY[0x284/4]= 0x80000077;
LPDDR1_PHY[0x54/4]= 0x10203;
LPDDR1_PHY[0x54/4]= 0x10203;
LPDDR1_PHY[0x54/4]= 0x10203;
LPDDR1_PHY[0x54/4]= 0x10203;
LPDDR1_PHY[0x58/4]= 0x4050607;
LPDDR1_PHY[0x58/4]= 0x4050607;
LPDDR1_PHY[0x640/4]= 0x10003;
LPDDR1_PHY[0x940/4]= 0x30003;
LPDDR1_PHY[0xc40/4]= 0x50003;
LPDDR1_PHY[0xf40/4]= 0x70003;


LPDDR1_PHY[0x6dc/4] = 0x45326170;
LPDDR1_PHY[0x9dc/4] = 0x35476021;
LPDDR1_PHY[0xcdc/4] = 0x67104352;
LPDDR1_PHY[0xfdc/4] = 0x10673524;




LPDDR1_PHY[0x2fc/4]= 0x7e00c00;
LPDDR1_PHY[0x24/4]= 0x1ff;
LPDDR1_PHY[0x24/4]= 0x1ff;
LPDDR1_PHY[0x280/4]= 0xf00fef;

//release system_rstn & ctrl_rstn

//printf("\n1 r rstn\n");


APB[0x0/4] = 0x2000000;


LPDDR1_CTRL[0x0/4]= 0x3d04515;
LPDDR1_CTRL[0x0/4]= 0x3f04515;
//PHY INIT complete [0]
while ((LPDDR1_CTRL[0x3b0/4] &  0x1)  == 0 );


LPDDR1_CTRL[0x0/4]= 0x3f04505;
LPDDR1_CTRL[0x0/4]= 0x3d04505;
LPDDR1_CTRL[0x3ac/4]= 0x3c0;
LPDDR1_CTRL[0x0/4]= 0x3d0450d;
//SDRAM INIT complete [2]
while ((LPDDR1_CTRL[0x3b0/4] & 0x4 ) == 0);

/*
//////////////////zqcalib//////////
LPDDR1_PHY[0x8C/4]=0x1;
while ((LPDDR1_PHY[0x1fc/4] & 0x10) != 0x10);
LPDDR1_PHY[0x8C/4]=0x0;

LPDDR1_PHY[0x400/4] |= 0x600000;
LPDDR1_PHY[0x700/4] |= 0x600000;
LPDDR1_PHY[0xd00/4] |= 0x600000;
LPDDR1_PHY[0xd00/4] |= 0x600000;


//////////////////zqcalib//////////
//++++++++++++++++++Command Training Start+++++++++++++++++++++++++++.

LPDDR1_PHY[0x400/4]=0x380800a0;
LPDDR1_PHY[0x400/4]=0x380800a0;
LPDDR1_PHY[0x700/4]=0x380800a0;
LPDDR1_PHY[0x700/4]=0x380800a0;
LPDDR1_PHY[0xa00/4]=0x380800a0;
LPDDR1_PHY[0xa00/4]=0x380800a0;
LPDDR1_PHY[0xd00/4]=0x380800a0;
LPDDR1_PHY[0xd00/4]=0x380800a0;
LPDDR1_PHY[0x24/4]=0x1ff;
LPDDR1_PHY[0x20/4]=0x66840;
LPDDR1_PHY[0x34/4]=0x32004d1f;
LPDDR1_PHY[0x3c/4]=0x3f97f3f;
LPDDR1_PHY[0x40/4]=0x3f7f7f7f;
LPDDR1_PHY[0x40/4]=0x3f3f7f7f;
LPDDR1_PHY[0x3c/4]=0x3f93f3f;
LPDDR1_PHY[0x40/4]=0x3f3f3f7f;
LPDDR1_PHY[0x40/4]=0x3f3f3f3f;
LPDDR1_PHY[0x20/4]=0x66840;
LPDDR1_PHY[0x20/4]=0x66840;
LPDDR1_PHY[0x38/4]=0x11c8;
LPDDR1_PHY[0xa0/4]=0x1000000;
LPDDR1_PHY[0x1c4/4]=0x100067aa;
LPDDR1_PHY[0x20/4]=0x66841;
LPDDR1_PHY[0x20/4]=0x66843;

while ((LPDDR1_PHY[0x214/4] & 0xc) != 0xc);

printf("command bus training: 0x%08x\n",LPDDR1_PHY[0x214/4]);

LPDDR1_PHY[0x20/4] =0x66841;
LPDDR1_PHY[0xc0/4] =0x3be00000;
LPDDR1_PHY[0x20/4] =0x66840;
LPDDR1_PHY[0x1b0/4]=0x14280140;
LPDDR1_PHY[0x1b0/4]=0x14280540;
LPDDR1_PHY[0x1b0/4]=0x14280940;
LPDDR1_PHY[0x1b0/4]=0x14280d40;
LPDDR1_PHY[0x1b0/4]=0x14281140;
LPDDR1_PHY[0x1b0/4]=0x14281540;
LPDDR1_PHY[0x1b0/4]=0x14283940;
LPDDR1_PHY[0x1b0/4]=0x14283d40;
LPDDR1_PHY[0x1b0/4]=0x14284140;
LPDDR1_PHY[0x1b0/4]=0x14284540;
LPDDR1_PHY[0x1b0/4]=0x14284940;
LPDDR1_PHY[0x1b0/4]=0x14284d40;
LPDDR1_PHY[0x400/4]=0x3a0800a0;
LPDDR1_PHY[0x700/4]=0x3a0800a0;
LPDDR1_PHY[0xa00/4]=0x3a0800a0;
LPDDR1_PHY[0xd00/4]=0x3a0800a0;
*/
//++++++++++++++++++Command Training end+++++++++++++++++++++++++++.

LPDDR1_CTRL[0x0/4]= 0x3d04505;
LPDDR1_CTRL[0x3ac/4]= 0x340;
LPDDR1_CTRL[0x0/4]= 0x3d04505;
LPDDR1_CTRL[0x74/4]= 0x10100;
LPDDR1_CTRL[0x74/4]= 0x10000;
LPDDR1_PHY[0x84/4]= 0x3592f;
LPDDR1_PHY[0x1c4/4]= 0x67aa;
LPDDR1_PHY[0xc4/4]= 0x30004;
LPDDR1_PHY[0x400/4]= 0x380800a0;
LPDDR1_PHY[0x700/4]= 0x380800a0;
LPDDR1_PHY[0xa00/4]= 0x380800a0;
LPDDR1_PHY[0xd00/4]= 0x380800a0;
LPDDR1_PHY[0x9c/4]= 0x350000;
LPDDR1_PHY[0xa0/4]= 0x1000000;
LPDDR1_PHY[0x4/4]= 0x8e38;
LPDDR1_PHY[0x4/4]= 0x928e38;
//The write-leveling training enable signal. High is valid.
//0xe = rank0
LPDDR1_PHY[0x4/4]= 0x928e78;
//bit 24- write-leveling finish


while((LPDDR1_PHY[0x20c/4] & 0x1000000) == 0);

//wl_done_byte[3:0] - [15:12]

//exit write leveling

LPDDR1_PHY[0x4/4]= 0x928e38;
LPDDR1_PHY[0x4/4]= 0x928038;
LPDDR1_PHY[0xa8/4]= 0xaf19880;
LPDDR1_PHY[0x9c/4]= 0x350000;
LPDDR1_PHY[0xa0/4]= 0x1000000;
LPDDR1_PHY[0x4/4]= 0x928d38;
LPDDR1_PHY[0x4/4]= 0x928d38;
//d=rank1
LPDDR1_PHY[0x4/4]= 0x928d78;


while((LPDDR1_PHY[0x20c/4] & 0x1000000) == 0);


LPDDR1_PHY[0x4/4]= 0x928d38;
LPDDR1_PHY[0x4/4]= 0x928038;
LPDDR1_PHY[0xa8/4]= 0xaf19880;
LPDDR1_PHY[0x2f8/4]= 0xc00a0;
LPDDR1_PHY[0x400/4]= 0x3a0800a0;
LPDDR1_PHY[0x700/4]= 0x3a0800a0;
LPDDR1_PHY[0xa00/4]= 0x3a0800a0;
LPDDR1_PHY[0xd00/4]= 0x3a0800a0;
LPDDR1_PHY[0x400/4]= 0x3a080080;
LPDDR1_PHY[0x400/4]= 0x3a0800c0;
LPDDR1_PHY[0x700/4]= 0x3a080080;
LPDDR1_PHY[0x700/4]= 0x3a0800c0;
LPDDR1_PHY[0xa00/4]= 0x3a080080;
LPDDR1_PHY[0xa00/4]= 0x3a0800c0;
LPDDR1_PHY[0xd00/4]= 0x3a080080;
LPDDR1_PHY[0xd00/4]= 0x3a0800c0;
LPDDR1_PHY[0x94/4]= 0x0;
LPDDR1_PHY[0x44/4]= 0x300120;
LPDDR1_PHY[0x4/4]= 0x928038;
LPDDR1_PHY[0x4/4]= 0x928039;
//bit[11],The rx dqs calib complete signal
while((LPDDR1_PHY[0x20c/4] & 0x800) == 0);



LPDDR1_PHY[0x4/4]= 0x928038;
LPDDR1_PHY[0x4/4]= 0x928030;
LPDDR1_PHY[0x94/4]= 0x0;
LPDDR1_PHY[0x44/4]= 0x300120;
LPDDR1_PHY[0x4/4]= 0x928034;
//The auto rx-dqs calibration training enable signal.
LPDDR1_PHY[0x4/4]= 0x928035;

//bit[11]
while((LPDDR1_PHY[0x20c/4] & 0x800) == 0);


LPDDR1_PHY[0x4/4]= 0x928034;
LPDDR1_PHY[0x4/4]= 0x928030;
LPDDR1_PHY[0x94/4]= 0x20000000;
LPDDR1_PHY[0xb0/4]= 0x5555555;
LPDDR1_PHY[0x94/4]= 0x20000e00;
LPDDR1_PHY[0xa8/4]= 0xaf19881;
LPDDR1_PHY[0x94/4]= 0x20000e00;

//byte remap
//LPDDR1_PHY[0x464/4]= 0x9600;
//LPDDR1_PHY[0x764/4]= 0x1500;
//LPDDR1_PHY[0xa64/4]= 0x6300;
//LPDDR1_PHY[0x764/4]= 0x4b00;

//LPDDR1_PHY[0x464/4]= 0x9900;
//LPDDR1_PHY[0x764/4]= 0xde00;
//LPDDR1_PHY[0xa64/4]= 0xe400;
//LPDDR1_PHY[0x764/4]= 0xd200;


//LPDDR1_PHY[0x464/4]= 0xcc00;
//LPDDR1_PHY[0x764/4]= 0x8b00;
//LPDDR1_PHY[0xa64/4]= 0xb100;
//LPDDR1_PHY[0x764/4]= 0x8700;


//1: Enable the auto train of the read train.
LPDDR1_PHY[0x94/4]= 0x20000e01;

//bit[0]-train_true_done
//The complete signal of the read training(mpr/mpc mode). Active high.
while((LPDDR1_PHY[0x1f0/4] & 0x1) == 0);

READ_DATA = LPDDR1_PHY[0x2a4/4] ;

//reg_train_done_for_rd_to_reg[13:10]
//reg_train_error_for_rd_byte [3:0]


LPDDR1_PHY[0x94/4]= 0x20000e00;
LPDDR1_PHY[0x94/4]= 0x20000e00;
LPDDR1_PHY[0x94/4]= 0x20000000;
LPDDR1_PHY[0xa8/4]= 0xaf19880;
LPDDR1_PHY[0x430/4]= 0x18080000;
LPDDR1_PHY[0x430/4]= 0x18088000;
LPDDR1_PHY[0x430/4]= 0x18090000;
LPDDR1_PHY[0x430/4]= 0x18098000;
LPDDR1_PHY[0x430/4]= 0x180a0000;
LPDDR1_PHY[0x430/4]= 0x180a8000;
LPDDR1_PHY[0x430/4]= 0x180b0000;
LPDDR1_PHY[0x430/4]= 0x180b8000;
LPDDR1_PHY[0x430/4]= 0x180c0000;
LPDDR1_PHY[0x730/4]= 0x18080000;
LPDDR1_PHY[0x730/4]= 0x18088000;
LPDDR1_PHY[0x730/4]= 0x18090000;
LPDDR1_PHY[0x730/4]= 0x18098000;
LPDDR1_PHY[0x730/4]= 0x180a0000;
LPDDR1_PHY[0x730/4]= 0x180a8000;
LPDDR1_PHY[0x730/4]= 0x180b0000;
LPDDR1_PHY[0x730/4]= 0x180b8000;
LPDDR1_PHY[0x730/4]= 0x180c0000;
LPDDR1_PHY[0xa30/4]= 0x18080000;
LPDDR1_PHY[0xa30/4]= 0x18088000;
LPDDR1_PHY[0xa30/4]= 0x18090000;
LPDDR1_PHY[0xa30/4]= 0x18098000;
LPDDR1_PHY[0xa30/4]= 0x180a0000;
LPDDR1_PHY[0xa30/4]= 0x180a8000;
LPDDR1_PHY[0xa30/4]= 0x180b0000;
LPDDR1_PHY[0xa30/4]= 0x180b8000;
LPDDR1_PHY[0xa30/4]= 0x180c0000;
LPDDR1_PHY[0xd30/4]= 0x18080000;
LPDDR1_PHY[0xd30/4]= 0x18088000;
LPDDR1_PHY[0xd30/4]= 0x18090000;
LPDDR1_PHY[0xd30/4]= 0x18098000;
LPDDR1_PHY[0xd30/4]= 0x180a0000;
LPDDR1_PHY[0xd30/4]= 0x180a8000;
LPDDR1_PHY[0xd30/4]= 0x180b0000;
LPDDR1_PHY[0xd30/4]= 0x180b8000;
LPDDR1_PHY[0xd30/4]= 0x180c0000;
LPDDR1_PHY[0x94/4]= 0x20000000;
LPDDR1_PHY[0xb0/4]= 0x5555555;
LPDDR1_PHY[0x94/4]= 0x20000d00;
LPDDR1_PHY[0xa8/4]= 0xaf19881;
LPDDR1_PHY[0x94/4]= 0x20000d00;
LPDDR1_PHY[0x94/4]= 0x20000d01;



//bit[0]
while((LPDDR1_PHY[0x1f0/4] & 0x1) == 0);

READ_DATA = LPDDR1_PHY[0x2a4/4] ;



LPDDR1_PHY[0x94/4]= 0x20000d00;
LPDDR1_PHY[0x94/4]= 0x20000d00;
LPDDR1_PHY[0x94/4]= 0x20000000;
LPDDR1_PHY[0xa8/4]= 0xaf19880;
LPDDR1_PHY[0x430/4]= 0x180c4000;
LPDDR1_PHY[0x430/4]= 0x180c4400;
LPDDR1_PHY[0x430/4]= 0x180c4800;
LPDDR1_PHY[0x430/4]= 0x180c4c00;
LPDDR1_PHY[0x430/4]= 0x180c5000;
LPDDR1_PHY[0x430/4]= 0x180c5400;
LPDDR1_PHY[0x430/4]= 0x180c5800;
LPDDR1_PHY[0x430/4]= 0x180c5c00;
LPDDR1_PHY[0x430/4]= 0x180c6000;
LPDDR1_PHY[0x730/4]= 0x180c4000;
LPDDR1_PHY[0x730/4]= 0x180c4400;
LPDDR1_PHY[0x730/4]= 0x180c4800;
LPDDR1_PHY[0x730/4]= 0x180c4c00;
LPDDR1_PHY[0x730/4]= 0x180c5000;
LPDDR1_PHY[0x730/4]= 0x180c5400;
LPDDR1_PHY[0x730/4]= 0x180c5800;
LPDDR1_PHY[0x730/4]= 0x180c5c00;
LPDDR1_PHY[0x730/4]= 0x180c6000;
LPDDR1_PHY[0xa30/4]= 0x180c4000;
LPDDR1_PHY[0xa30/4]= 0x180c4400;
LPDDR1_PHY[0xa30/4]= 0x180c4800;
LPDDR1_PHY[0xa30/4]= 0x180c4c00;
LPDDR1_PHY[0xa30/4]= 0x180c5000;
LPDDR1_PHY[0xa30/4]= 0x180c5400;
LPDDR1_PHY[0xa30/4]= 0x180c5800;
LPDDR1_PHY[0xa30/4]= 0x180c5c00;
LPDDR1_PHY[0xa30/4]= 0x180c6000;
LPDDR1_PHY[0xd30/4]= 0x180c4000;
LPDDR1_PHY[0xd30/4]= 0x180c4400;
LPDDR1_PHY[0xd30/4]= 0x180c4800;
LPDDR1_PHY[0xd30/4]= 0x180c4c00;
LPDDR1_PHY[0xd30/4]= 0x180c5000;
LPDDR1_PHY[0xd30/4]= 0x180c5400;
LPDDR1_PHY[0xd30/4]= 0x180c5800;
LPDDR1_PHY[0xd30/4]= 0x180c5c00;
LPDDR1_PHY[0xd30/4]= 0x180c6000;
LPDDR1_PHY[0x468/4]= 0x80080;
LPDDR1_PHY[0x768/4]= 0x80080;
LPDDR1_PHY[0xa68/4]= 0x80080;
LPDDR1_PHY[0xd68/4]= 0x80080;
LPDDR1_PHY[0xa0/4]= 0x5000000;
LPDDR1_PHY[0x468/4]= 0xff880;
LPDDR1_PHY[0x768/4]= 0xff880;
LPDDR1_PHY[0xa68/4]= 0xff880;
LPDDR1_PHY[0xd68/4]= 0xff880;
LPDDR1_PHY[0xa0/4]= 0x7000000;
LPDDR1_PHY[0xa0/4]= 0x7000000;
LPDDR1_PHY[0x1bc/4]= 0x2b5f3892;
LPDDR1_PHY[0x1bc/4]= 0x2b5f3892;
LPDDR1_PHY[0x1bc/4]= 0x2b5f3892;
LPDDR1_PHY[0x1bc/4]= 0x2b5f3892;
LPDDR1_PHY[0x1c0/4]= 0xadbdb174;
LPDDR1_PHY[0x1c0/4]= 0xadbdb174;
LPDDR1_PHY[0x1c0/4]= 0xadbdb174;
LPDDR1_PHY[0x1c0/4]= 0xadbdb174;
LPDDR1_PHY[0x1c4/4]= 0x67aa;
LPDDR1_PHY[0x1c4/4]= 0x67aa;
LPDDR1_PHY[0x2f0/4]= 0x3f100cc5;
LPDDR1_PHY[0x2f0/4]= 0x3f100cc5;
LPDDR1_PHY[0x2f0/4]= 0x3f100cc5;
LPDDR1_PHY[0x2f0/4]= 0x3f100cc5;
LPDDR1_PHY[0x2f4/4]= 0x13cd;
LPDDR1_PHY[0x2f4/4]= 0x13cd;
LPDDR1_PHY[0x150/4]= 0x2b5f3892;
LPDDR1_PHY[0x150/4]= 0x2b5f3892;
LPDDR1_PHY[0x150/4]= 0x2b5f3892;
LPDDR1_PHY[0x150/4]= 0x2b5f3892;
LPDDR1_PHY[0x154/4]= 0xadbdb174;
LPDDR1_PHY[0x154/4]= 0xadbdb174;
LPDDR1_PHY[0x154/4]= 0xadbdb174;
LPDDR1_PHY[0x154/4]= 0xadbdb174;
LPDDR1_PHY[0x158/4]= 0x67aa;
LPDDR1_PHY[0x158/4]= 0x67aa;
LPDDR1_PHY[0x2c0/4]= 0x3f100cc5;
LPDDR1_PHY[0x2c0/4]= 0x3f100cc5;
LPDDR1_PHY[0x2c0/4]= 0x3f100cc5;
LPDDR1_PHY[0x2c0/4]= 0x3f100cc5;
LPDDR1_PHY[0x2c4/4]= 0x13cde148;
LPDDR1_PHY[0x2c4/4]= 0x13cde148;
LPDDR1_PHY[0x15c/4]= 0x3b53fd81;
LPDDR1_PHY[0x15c/4]= 0x3b53fd81;
LPDDR1_PHY[0x15c/4]= 0x3b53fd81;
LPDDR1_PHY[0x15c/4]= 0x3b53fd81;
LPDDR1_PHY[0x160/4]= 0x60289e68;
LPDDR1_PHY[0x160/4]= 0x60289e68;
LPDDR1_PHY[0x160/4]= 0x60289e68;
LPDDR1_PHY[0x160/4]= 0x60289e68;
LPDDR1_PHY[0x164/4]= 0xae7c;
LPDDR1_PHY[0x164/4]= 0xae7c;
LPDDR1_PHY[0x2c4/4]= 0x13cde148;
LPDDR1_PHY[0x2c4/4]= 0x13cde148;
LPDDR1_PHY[0x2c8/4]= 0xb6f6c6d2;
LPDDR1_PHY[0x2c8/4]= 0xb6f6c6d2;
LPDDR1_PHY[0x2c8/4]= 0xb6f6c6d2;
LPDDR1_PHY[0x2c8/4]= 0xb6f6c6d2;
LPDDR1_PHY[0x168/4]= 0x20188a27;
LPDDR1_PHY[0x168/4]= 0x20188a27;
LPDDR1_PHY[0x168/4]= 0x20188a27;
LPDDR1_PHY[0x168/4]= 0x20188a27;
LPDDR1_PHY[0x16c/4]= 0x9a2b5f38;
LPDDR1_PHY[0x16c/4]= 0x9a2b5f38;
LPDDR1_PHY[0x16c/4]= 0x9a2b5f38;
LPDDR1_PHY[0x16c/4]= 0x9a2b5f38;
LPDDR1_PHY[0x170/4]= 0x92ad;
LPDDR1_PHY[0x170/4]= 0x92ad;
LPDDR1_PHY[0x2cc/4]= 0xbdb17467;
LPDDR1_PHY[0x2cc/4]= 0xbdb17467;
LPDDR1_PHY[0x2cc/4]= 0xbdb17467;
LPDDR1_PHY[0x2cc/4]= 0xbdb17467;
LPDDR1_PHY[0x2d0/4]= 0xaa3fc291;
LPDDR1_PHY[0x2d0/4]= 0xaa3fc291;
LPDDR1_PHY[0x174/4]= 0x77a6fa03;
LPDDR1_PHY[0x174/4]= 0x77a6fa03;
LPDDR1_PHY[0x174/4]= 0x77a6fa03;
LPDDR1_PHY[0x174/4]= 0x77a6fa03;
LPDDR1_PHY[0x178/4]= 0xc1503cd1;
LPDDR1_PHY[0x178/4]= 0xc1503cd1;
LPDDR1_PHY[0x178/4]= 0xc1503cd1;
LPDDR1_PHY[0x178/4]= 0xc1503cd1;
LPDDR1_PHY[0x17c/4]= 0x5cf9;
LPDDR1_PHY[0x17c/4]= 0x5cf9;
LPDDR1_PHY[0x2d0/4]= 0xaa3fc291;
LPDDR1_PHY[0x2d0/4]= 0xaa3fc291;
LPDDR1_PHY[0x2d4/4]= 0x6ced8da5;
LPDDR1_PHY[0x2d4/4]= 0x6ced8da5;
LPDDR1_PHY[0x2d4/4]= 0x6ced8da5;
LPDDR1_PHY[0x2d4/4]= 0x6ced8da5;
LPDDR1_PHY[0x180/4]= 0x5b7b63e9;
LPDDR1_PHY[0x180/4]= 0x5b7b63e9;
LPDDR1_PHY[0x180/4]= 0x5b7b63e9;
LPDDR1_PHY[0x180/4]= 0x5b7b63e9;
LPDDR1_PHY[0x184/4]= 0xce547f20;
LPDDR1_PHY[0x184/4]= 0xce547f20;
LPDDR1_PHY[0x184/4]= 0xce547f20;
LPDDR1_PHY[0x184/4]= 0xce547f20;
LPDDR1_PHY[0x188/4]= 0x188a;
LPDDR1_PHY[0x188/4]= 0x188a;
LPDDR1_PHY[0x2d8/4]= 0x279a2b5f;
LPDDR1_PHY[0x2d8/4]= 0x279a2b5f;
LPDDR1_PHY[0x2d8/4]= 0x279a2b5f;
LPDDR1_PHY[0x2d8/4]= 0x279a2b5f;
LPDDR1_PHY[0x2dc/4]= 0x38923892;
LPDDR1_PHY[0x2dc/4]= 0x38923892;
LPDDR1_PHY[0x18c/4]= 0xce547f20;
LPDDR1_PHY[0x18c/4]= 0xce547f20;
LPDDR1_PHY[0x18c/4]= 0xce547f20;
LPDDR1_PHY[0x18c/4]= 0xce547f20;
LPDDR1_PHY[0x190/4]= 0x188a279a;
LPDDR1_PHY[0x190/4]= 0x188a279a;
LPDDR1_PHY[0x190/4]= 0x188a279a;
LPDDR1_PHY[0x190/4]= 0x188a279a;
LPDDR1_PHY[0x194/4]= 0x2b5f;
LPDDR1_PHY[0x194/4]= 0x2b5f;
LPDDR1_PHY[0x2dc/4]= 0x38923892;
LPDDR1_PHY[0x2dc/4]= 0x38923892;
LPDDR1_PHY[0x2e0/4]= 0xadbdb174;
LPDDR1_PHY[0x2e0/4]= 0xadbdb174;
LPDDR1_PHY[0x2e0/4]= 0xadbdb174;
LPDDR1_PHY[0x2e0/4]= 0xadbdb174;
LPDDR1_PHY[0x198/4]= 0xd6de58ba;
LPDDR1_PHY[0x198/4]= 0xd6de58ba;
LPDDR1_PHY[0x198/4]= 0xd6de58ba;
LPDDR1_PHY[0x198/4]= 0xd6de58ba;
LPDDR1_PHY[0x19c/4]= 0x33d51f08;
LPDDR1_PHY[0x19c/4]= 0x33d51f08;
LPDDR1_PHY[0x19c/4]= 0x33d51f08;
LPDDR1_PHY[0x19c/4]= 0x33d51f08;
LPDDR1_PHY[0x1a0/4]= 0x86e2;
LPDDR1_PHY[0x1a0/4]= 0x86e2;
LPDDR1_PHY[0x2e4/4]= 0x89e6ca17;
LPDDR1_PHY[0x2e4/4]= 0x89e6ca17;
LPDDR1_PHY[0x2e4/4]= 0x89e6ca17;
LPDDR1_PHY[0x2e4/4]= 0x89e6ca17;
LPDDR1_PHY[0x2e8/4]= 0x8e641b4b;
LPDDR1_PHY[0x2e8/4]= 0x8e641b4b;
LPDDR1_PHY[0x1a4/4]= 0x82a178a2;
LPDDR1_PHY[0x1a4/4]= 0x82a178a2;
LPDDR1_PHY[0x1a4/4]= 0x82a178a2;
LPDDR1_PHY[0x1a4/4]= 0x82a178a2;
LPDDR1_PHY[0x1a8/4]= 0xb9f28523;
LPDDR1_PHY[0x1a8/4]= 0xb9f28523;
LPDDR1_PHY[0x1a8/4]= 0xb9f28523;
LPDDR1_PHY[0x1a8/4]= 0xb9f28523;
LPDDR1_PHY[0x1ac/4]= 0x1d9da;
LPDDR1_PHY[0x1ac/4]= 0x1d9da;
LPDDR1_PHY[0x2e8/4]= 0x8e641b4b;
LPDDR1_PHY[0x2e8/4]= 0x8e641b4b;
LPDDR1_PHY[0x2ec/4]= 0x77a6fa03;
LPDDR1_PHY[0x2ec/4]= 0x77a6fa03;
LPDDR1_PHY[0x2ec/4]= 0x77a6fa03;
LPDDR1_PHY[0x2ec/4]= 0x77a6fa03;
LPDDR1_PHY[0xa0/4]= 0x7000380;
LPDDR1_PHY[0xa8/4]= 0xaf19881;
LPDDR1_PHY[0xa0/4]= 0x7000382;
LPDDR1_PHY[0xa0/4]= 0x7000382;
LPDDR1_PHY[0x1c4/4]= 0x67aa;
LPDDR1_PHY[0xa0/4]= 0x17000382;
//dm read train enable:
LPDDR1_PHY[0x1c4/4]= 0x80067aa;

//bit[6]

//bit6-train_step1_delay_done
while((LPDDR1_PHY[0x1f0/4] & 0x40) == 0);

//bit[7]-train_all_step_done


while((LPDDR1_PHY[0x1f0/4] & 0x80) == 0);


READ_DATA = LPDDR1_PHY[0x1f0/4];
READ_DATA = LPDDR1_PHY[0x1f0/4];
READ_DATA = LPDDR1_PHY[0x1f0/4];




LPDDR1_PHY[0xa0/4]= 0x17000380;
LPDDR1_PHY[0xa0/4]= 0x17000380;
LPDDR1_PHY[0xa0/4]= 0x17000000;
LPDDR1_PHY[0xa8/4]= 0xaf19880;
LPDDR1_PHY[0xa0/4]= 0x17000000;
LPDDR1_PHY[0x1bc/4]= 0x2b5f3892;
LPDDR1_PHY[0x1bc/4]= 0x2b5f3892;
LPDDR1_PHY[0x1bc/4]= 0x2b5f3892;
LPDDR1_PHY[0x1bc/4]= 0x2b5f3892;
LPDDR1_PHY[0x1c0/4]= 0xadbdb174;
LPDDR1_PHY[0x1c0/4]= 0xadbdb174;
LPDDR1_PHY[0x1c0/4]= 0xadbdb174;
LPDDR1_PHY[0x1c0/4]= 0xadbdb174;
LPDDR1_PHY[0x1c4/4]= 0x80067aa;
LPDDR1_PHY[0x1c4/4]= 0x80067aa;
LPDDR1_PHY[0x2f0/4]= 0x3f100cc5;
LPDDR1_PHY[0x2f0/4]= 0x3f100cc5;
LPDDR1_PHY[0x2f0/4]= 0x3f100cc5;
LPDDR1_PHY[0x2f0/4]= 0x3f100cc5;
LPDDR1_PHY[0x2f4/4]= 0x13cd;
LPDDR1_PHY[0x2f4/4]= 0x13cd;
LPDDR1_PHY[0x150/4]= 0x2b5f3892;
LPDDR1_PHY[0x150/4]= 0x2b5f3892;
LPDDR1_PHY[0x150/4]= 0x2b5f3892;
LPDDR1_PHY[0x150/4]= 0x2b5f3892;
LPDDR1_PHY[0x154/4]= 0xadbdb174;
LPDDR1_PHY[0x154/4]= 0xadbdb174;
LPDDR1_PHY[0x154/4]= 0xadbdb174;
LPDDR1_PHY[0x154/4]= 0xadbdb174;
LPDDR1_PHY[0x158/4]= 0x67aa;
LPDDR1_PHY[0x158/4]= 0x67aa;
LPDDR1_PHY[0x2c0/4]= 0x3f100cc5;
LPDDR1_PHY[0x2c0/4]= 0x3f100cc5;
LPDDR1_PHY[0x2c0/4]= 0x3f100cc5;
LPDDR1_PHY[0x2c0/4]= 0x3f100cc5;
LPDDR1_PHY[0x2c4/4]= 0x13cde148;
LPDDR1_PHY[0x2c4/4]= 0x13cde148;
LPDDR1_PHY[0x15c/4]= 0x3b53fd81;
LPDDR1_PHY[0x15c/4]= 0x3b53fd81;
LPDDR1_PHY[0x15c/4]= 0x3b53fd81;
LPDDR1_PHY[0x15c/4]= 0x3b53fd81;
LPDDR1_PHY[0x160/4]= 0x60289e68;
LPDDR1_PHY[0x160/4]= 0x60289e68;
LPDDR1_PHY[0x160/4]= 0x60289e68;
LPDDR1_PHY[0x160/4]= 0x60289e68;
LPDDR1_PHY[0x164/4]= 0xae7c;
LPDDR1_PHY[0x164/4]= 0xae7c;
LPDDR1_PHY[0x2c4/4]= 0x13cde148;
LPDDR1_PHY[0x2c4/4]= 0x13cde148;
LPDDR1_PHY[0x2c8/4]= 0xb6f6c6d2;
LPDDR1_PHY[0x2c8/4]= 0xb6f6c6d2;
LPDDR1_PHY[0x2c8/4]= 0xb6f6c6d2;
LPDDR1_PHY[0x2c8/4]= 0xb6f6c6d2;
LPDDR1_PHY[0x168/4]= 0x20188a27;
LPDDR1_PHY[0x168/4]= 0x20188a27;
LPDDR1_PHY[0x168/4]= 0x20188a27;
LPDDR1_PHY[0x168/4]= 0x20188a27;
LPDDR1_PHY[0x16c/4]= 0x9a2b5f38;
LPDDR1_PHY[0x16c/4]= 0x9a2b5f38;
LPDDR1_PHY[0x16c/4]= 0x9a2b5f38;
LPDDR1_PHY[0x16c/4]= 0x9a2b5f38;
LPDDR1_PHY[0x170/4]= 0x92ad;
LPDDR1_PHY[0x170/4]= 0x92ad;
LPDDR1_PHY[0x2cc/4]= 0xbdb17467;
LPDDR1_PHY[0x2cc/4]= 0xbdb17467;
LPDDR1_PHY[0x2cc/4]= 0xbdb17467;
LPDDR1_PHY[0x2cc/4]= 0xbdb17467;
LPDDR1_PHY[0x2d0/4]= 0xaa3fc291;
LPDDR1_PHY[0x2d0/4]= 0xaa3fc291;
LPDDR1_PHY[0x174/4]= 0x77a6fa03;
LPDDR1_PHY[0x174/4]= 0x77a6fa03;
LPDDR1_PHY[0x174/4]= 0x77a6fa03;
LPDDR1_PHY[0x174/4]= 0x77a6fa03;
LPDDR1_PHY[0x178/4]= 0xc1503cd1;
LPDDR1_PHY[0x178/4]= 0xc1503cd1;
LPDDR1_PHY[0x178/4]= 0xc1503cd1;
LPDDR1_PHY[0x178/4]= 0xc1503cd1;
LPDDR1_PHY[0x17c/4]= 0x5cf9;
LPDDR1_PHY[0x17c/4]= 0x5cf9;
LPDDR1_PHY[0x2d0/4]= 0xaa3fc291;
LPDDR1_PHY[0x2d0/4]= 0xaa3fc291;
LPDDR1_PHY[0x2d4/4]= 0x6ced8da5;
LPDDR1_PHY[0x2d4/4]= 0x6ced8da5;
LPDDR1_PHY[0x2d4/4]= 0x6ced8da5;
LPDDR1_PHY[0x2d4/4]= 0x6ced8da5;
LPDDR1_PHY[0x180/4]= 0x5b7b63e9;
LPDDR1_PHY[0x180/4]= 0x5b7b63e9;
LPDDR1_PHY[0x180/4]= 0x5b7b63e9;
LPDDR1_PHY[0x180/4]= 0x5b7b63e9;
LPDDR1_PHY[0x184/4]= 0xce547f20;
LPDDR1_PHY[0x184/4]= 0xce547f20;
LPDDR1_PHY[0x184/4]= 0xce547f20;
LPDDR1_PHY[0x184/4]= 0xce547f20;
LPDDR1_PHY[0x188/4]= 0x188a;
LPDDR1_PHY[0x188/4]= 0x188a;
LPDDR1_PHY[0x2d8/4]= 0x279a2b5f;
LPDDR1_PHY[0x2d8/4]= 0x279a2b5f;
LPDDR1_PHY[0x2d8/4]= 0x279a2b5f;
LPDDR1_PHY[0x2d8/4]= 0x279a2b5f;
LPDDR1_PHY[0x2dc/4]= 0x38923892;
LPDDR1_PHY[0x2dc/4]= 0x38923892;
LPDDR1_PHY[0x18c/4]= 0xce547f20;
LPDDR1_PHY[0x18c/4]= 0xce547f20;
LPDDR1_PHY[0x18c/4]= 0xce547f20;
LPDDR1_PHY[0x18c/4]= 0xce547f20;
LPDDR1_PHY[0x190/4]= 0x188a279a;
LPDDR1_PHY[0x190/4]= 0x188a279a;
LPDDR1_PHY[0x190/4]= 0x188a279a;
LPDDR1_PHY[0x190/4]= 0x188a279a;
LPDDR1_PHY[0x194/4]= 0x2b5f;
LPDDR1_PHY[0x194/4]= 0x2b5f;
LPDDR1_PHY[0x2dc/4]= 0x38923892;
LPDDR1_PHY[0x2dc/4]= 0x38923892;
LPDDR1_PHY[0x2e0/4]= 0xadbdb174;
LPDDR1_PHY[0x2e0/4]= 0xadbdb174;
LPDDR1_PHY[0x2e0/4]= 0xadbdb174;
LPDDR1_PHY[0x2e0/4]= 0xadbdb174;
LPDDR1_PHY[0x198/4]= 0xd6de58ba;
LPDDR1_PHY[0x198/4]= 0xd6de58ba;
LPDDR1_PHY[0x198/4]= 0xd6de58ba;
LPDDR1_PHY[0x198/4]= 0xd6de58ba;
LPDDR1_PHY[0x19c/4]= 0x33d51f08;
LPDDR1_PHY[0x19c/4]= 0x33d51f08;
LPDDR1_PHY[0x19c/4]= 0x33d51f08;
LPDDR1_PHY[0x19c/4]= 0x33d51f08;
LPDDR1_PHY[0x1a0/4]= 0x86e2;
LPDDR1_PHY[0x1a0/4]= 0x86e2;
LPDDR1_PHY[0x2e4/4]= 0x89e6ca17;
LPDDR1_PHY[0x2e4/4]= 0x89e6ca17;
LPDDR1_PHY[0x2e4/4]= 0x89e6ca17;
LPDDR1_PHY[0x2e4/4]= 0x89e6ca17;
LPDDR1_PHY[0x2e8/4]= 0x8e641b4b;
LPDDR1_PHY[0x2e8/4]= 0x8e641b4b;
LPDDR1_PHY[0x1a4/4]= 0x82a178a2;
LPDDR1_PHY[0x1a4/4]= 0x82a178a2;
LPDDR1_PHY[0x1a4/4]= 0x82a178a2;
LPDDR1_PHY[0x1a4/4]= 0x82a178a2;
LPDDR1_PHY[0x1a8/4]= 0xb9f28523;
LPDDR1_PHY[0x1a8/4]= 0xb9f28523;
LPDDR1_PHY[0x1a8/4]= 0xb9f28523;
LPDDR1_PHY[0x1a8/4]= 0xb9f28523;
LPDDR1_PHY[0x1ac/4]= 0x1d9da;
LPDDR1_PHY[0x1ac/4]= 0x1d9da;
LPDDR1_PHY[0x2e8/4]= 0x8e641b4b;
LPDDR1_PHY[0x2e8/4]= 0x8e641b4b;
LPDDR1_PHY[0x2ec/4]= 0x77a6fa03;
LPDDR1_PHY[0x2ec/4]= 0x77a6fa03;
LPDDR1_PHY[0x2ec/4]= 0x77a6fa03;
LPDDR1_PHY[0x2ec/4]= 0x77a6fa03;
LPDDR1_PHY[0xa0/4]= 0x17000340;
LPDDR1_PHY[0xa8/4]= 0xaf19881;
LPDDR1_PHY[0xa0/4]= 0x17000342;
LPDDR1_PHY[0xa0/4]= 0x7000342;
LPDDR1_PHY[0x1c4/4]= 0x67aa;
LPDDR1_PHY[0xa0/4]= 0x17000342;
LPDDR1_PHY[0x1c4/4]= 0x80067aa;

//bit[6]
while((LPDDR1_PHY[0x1f0/4] & 0x40) == 0);
//bit[7]
while((LPDDR1_PHY[0x1f0/4] & 0x80) == 0);

READ_DATA = LPDDR1_PHY[0x1f0/4];
READ_DATA = LPDDR1_PHY[0x1f0/4];
READ_DATA = LPDDR1_PHY[0x1f0/4];



LPDDR1_PHY[0xa0/4]= 0x17000340;
LPDDR1_PHY[0xa0/4]= 0x17000340;
LPDDR1_PHY[0xa0/4]= 0x17000000;

//printf("aa PHY: 0x%08x\n",LPDDR1_PHY[0x1f0/4]);

LPDDR1_PHY[0xa8/4]= 0xaf19880;

//printf("aa PHY: 0x%08x\n",LPDDR1_PHY[0x1f0/4]);

LPDDR1_CTRL[0x0/4]= 0x3c04505;
LPDDR1_CTRL[0x2e8/4]= 0x30202;
LPDDR1_CTRL[0x2e8/4]= 0x400202;
LPDDR1_CTRL[0x5a0/4]= 0x600;
LPDDR1_CTRL[0x5a0/4]= 0x637;
LPDDR1_CTRL[0x2e8/4]= 0x400212;
LPDDR1_CTRL[0x2e8/4]= 0x400202;
LPDDR1_CTRL[0x598/4]= 0x2008;
LPDDR1_CTRL[0x3ac/4]= 0x340;
LPDDR1_CTRL[0xa0/4]= 0x2000d00;
LPDDR1_CTRL[0xc0/4]= 0x2000d00;
LPDDR1_CTRL[0x120/4]= 0x11;
LPDDR1_CTRL[0x120/4]= 0x1;


APB[0x0/4] = 0x0;

}
